gm_json.py: add ability to load JSON file from a string, not just a local file

This will make it easier to read JSON files from new sources (HTTP, etc.)

R=scroggo@google.com

Review URL: https://codereview.chromium.org/15934018

git-svn-id: http://skia.googlecode.com/svn/trunk@9431 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/display_json_results.py b/gm/display_json_results.py
index 4c4605f..647e251 100644
--- a/gm/display_json_results.py
+++ b/gm/display_json_results.py
@@ -94,7 +94,7 @@
   }
 
   success = True
-  json_dict = gm_json.Load(filepath)
+  json_dict = gm_json.LoadFromFile(filepath)
   actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS]
   for label, accumulator in results_map.iteritems():
     results = actual_results[label]
diff --git a/gm/gm_json.py b/gm/gm_json.py
index 04c0d6a..6ba3a26 100644
--- a/gm/gm_json.py
+++ b/gm/gm_json.py
@@ -23,12 +23,19 @@
 JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
 JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
 
-def Load(filepath):
+def LoadFromString(file_contents):
   """Loads the JSON summary written out by the GM tool.
      Returns a dictionary keyed by the values listed as JSONKEY_ constants
      above."""
-  # In the future, we should add a version number to the JSON file to ensure
+  # TODO(epoger): we should add a version number to the JSON file to ensure
   # that the writer and reader agree on the schema (raising an exception
   # otherwise).
-  json_dict = json.load(open(filepath))
+  json_dict = json.loads(file_contents)
   return json_dict
+
+def LoadFromFile(file_path):
+  """Loads the JSON summary written out by the GM tool.
+     Returns a dictionary keyed by the values listed as JSONKEY_ constants
+     above."""
+  file_contents = open(file_path, 'r').read()
+  return LoadFromString(file_contents)