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

Side by Side Diff: tools/chrome_remote_control/chrome_remote_control/browser_credentials.py

Issue 10914237: Port perf.py's _LoginToGoogleAccount to chrome_remote_control (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from chrome_remote_control import google_credentials_backend
6 import logging
7 import json
8
9 class BrowserCredentials(object):
10 def __init__(self):
11 self._config = None
12 self._config_file = None
13
14 self._credentials_backends = \
15 [google_credentials_backend.GoogleCredentialsBackend(self)]
16
17 def _GetCredentialsBackend(self, credentials_type):
18 for backend in self._credentials_backends:
19 if credentials_type == backend.label:
20 return backend
21
22 def LoginNeeded(self, credentials_type, tab):
23 backend = self._GetCredentialsBackend(credentials_type)
24 if backend:
25 backend.LoginNeeded(tab)
26 else:
27 logging.warning('Credentials not implemented: "%s"', credentials_type)
28
29 def LoginNoLongerNeeded(self, credentials_type, tab):
30 backend = self._GetCredentialsBackend(credentials_type)
31 if backend:
32 backend.LoginNoLongerNeeded(tab)
33 else:
34 logging.warning('Credentials not implemented: "%s"', credentials_type)
35
36 def _ReadConfigFile(self):
37 try:
38 with open(self._config_file, 'r') as f:
39 contents = f.read()
40 return json.loads(contents)
41 except SyntaxError, e:
42 logging.info('Could not read %s: %s', self._config_file,
43 str(e))
44
45 def GetConfig(self, config):
46 if self._config is None:
47 self._config = self._ReadConfigFile()
48
49 for key in self._config:
50 if self._config.get(key) is not None and key in config:
51 config[key] = self._config.get(key)
52
53 return config
54
55 def GetCredentialsConfigFile(self):
56 return self._config_file
57
58 def SetCredentialsConfigFile(self, credentials_path):
59 self._config_file = credentials_path
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698