Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Unified Diff: tools/android/loading/frontend/clovis_task.py

Issue 1878943013: tools/android/loading Add appengine frontend for Clovis (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor
Patch Set: Improve documentation Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/android/loading/frontend/clovis_task.py
diff --git a/tools/android/loading/frontend/clovis_task.py b/tools/android/loading/frontend/clovis_task.py
new file mode 100644
index 0000000000000000000000000000000000000000..e7abf4e2e1755efe8ca5a743c088ba44e1f3edfb
--- /dev/null
+++ b/tools/android/loading/frontend/clovis_task.py
@@ -0,0 +1,63 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import base64
+import json
+
+class ClovisTask(object):
+ """Generic task, generated by the AppEngine frontend and consumed by the
+ ComputeEngine backend.
+ """
+
+ def __init__(self, action, params, taskqueue_tag):
+ """Params:
+ action(str): Action accomplished by this task..
blundell 2016/04/19 11:05:25 nit: two periods
droger 2016/04/19 11:38:29 Done.
+ params(dict): Parameters of task.
+ taskqueue_tag(str): Tag of the task. Optional.
+ """
+ self._action = action
+ self._params = params
+ self._taskqueue_tag = taskqueue_tag
+
+ @classmethod
+ def FromJson(cls, json_dict):
blundell 2016/04/19 11:05:25 nit: FromJsonDict
droger 2016/04/19 11:38:29 Done.
+ """Loads a ClovisTask from a JSON string.
+
+ Returns:
+ ClovisTask: The task, or None if the string is invalid.
+ """
+ try:
+ data = json.loads(json_dict)
+ action = data['action']
+ params = data['params']
+ tag = data.get('taskqueue_tag')
+ # Vaidate the format.
+ if action == 'trace':
+ urls = params['urls']
+ if (type(urls) is not list) or (len(urls) == 0):
+ return None
+ else:
+ # When more actions are supported, check that they are valid here.
+ return None
+ return cls(action, params, tag)
+ except Exception:
+ return None
+
+ @classmethod
+ def FromBase64(cls, base64_string):
+ """Loads a ClovisTask from a base 64 string."""
+ return ClovisTask.FromJson(base64.b64decode(base64_string))
+
+ def ToJson(self):
blundell 2016/04/19 11:05:25 nit: ToJsonDict
droger 2016/04/19 11:38:29 Done.
+ """Returns the JSON representation of the task."""
+ return json.dumps( { 'action': self._action, 'params': self._params })
+
+ def Action(self):
+ return self._action
+
+ def Params(self):
+ return self._params
+
+ def TaskqueueTag(self):
+ return self._taskqueue_tag

Powered by Google App Engine
This is Rietveld 408576698