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

Side by Side Diff: components/login/screens/screen_context.h

Issue 755203002: Added usage of ScreenContext in EulaScreen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments. Created 6 years 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_LOGIN_SCREENS_SCREEN_CONTEXT_H_ 5 #ifndef COMPONENTS_LOGIN_SCREENS_SCREEN_CONTEXT_H_
6 #define COMPONENTS_LOGIN_SCREENS_SCREEN_CONTEXT_H_ 6 #define COMPONENTS_LOGIN_SCREENS_SCREEN_CONTEXT_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/callback_list.h"
14 #include "base/containers/hash_tables.h"
12 #include "base/containers/hash_tables.h" 15 #include "base/containers/hash_tables.h"
13 #include "base/logging.h" 16 #include "base/logging.h"
14 #include "base/memory/linked_ptr.h" 17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
16 #include "base/threading/non_thread_safe.h" 20 #include "base/threading/non_thread_safe.h"
17 #include "base/values.h" 21 #include "base/values.h"
18 #include "components/login/base_screen_handler_utils.h" 22 #include "components/login/base_screen_handler_utils.h"
19 #include "components/login/login_export.h" 23 #include "components/login/login_export.h"
20 24
21 namespace login { 25 namespace login {
22 26
23 // ScreenContext is a key-value storage for values that are shared 27 // ScreenContext is a key-value storage for values that are shared
24 // between C++ and JS sides. Objects of this class should be used in 28 // between C++ and JS sides. Objects of this class should be used in
25 // the following way: 29 // the following way:
26 // 30 //
27 // context.SetString("user", "john"); 31 // context.SetString("user", "john");
28 // context.SetInteger("image-index", 0); 32 // context.SetInteger("image-index", 0);
29 // context.SetDouble("zoom", 1.25); 33 // context.SetDouble("zoom", 1.25);
30 // context.GetChangesAndReset(&dictionary); 34 // context.GetChangesAndReset(&dictionary);
31 // CallJS("onContextChanged", dictionary); 35 // CallJS("onContextChanged", dictionary);
32 // 36 //
33 // ScreenContext memorizes changed key-value pairs and returns them 37 // ScreenContext memorizes changed key-value pairs and returns them
34 // via GetChangesAndReset() method. After call to this method an 38 // via GetChangesAndReset() method. After call to this method an
35 // internal buffer of changes will be cleared. 39 // internal buffer of changes will be cleared.
36 class LOGIN_EXPORT ScreenContext : public base::NonThreadSafe { 40 class LOGIN_EXPORT ScreenContext : public base::NonThreadSafe {
37 public: 41 public:
38 typedef std::string KeyType; 42 typedef std::string KeyType;
39 typedef base::Value ValueType; 43 typedef base::Value ValueType;
44 typedef base::Callback<void(const KeyType& key, const base::Value& value)>
45 KeyObserver;
46 typedef base::CallbackList<KeyObserver::RunType> KeyObserversList;
47 typedef KeyObserversList::Subscription KeyObserverSubscription;
40 48
41 ScreenContext(); 49 ScreenContext();
42 ~ScreenContext(); 50 ~ScreenContext();
43 51
44 bool SetBoolean(const KeyType& key, bool value); 52 bool SetBoolean(const KeyType& key, bool value);
45 bool SetInteger(const KeyType& key, int value); 53 bool SetInteger(const KeyType& key, int value);
46 bool SetDouble(const KeyType& key, double value); 54 bool SetDouble(const KeyType& key, double value);
47 bool SetString(const KeyType& key, const std::string& value); 55 bool SetString(const KeyType& key, const std::string& value);
48 bool SetString(const KeyType& key, const base::string16& value); 56 bool SetString(const KeyType& key, const base::string16& value);
49 bool SetStringList(const KeyType& key, const StringList& value); 57 bool SetStringList(const KeyType& key, const StringList& value);
(...skipping 11 matching lines...) Expand all
61 base::string16 GetString16(const KeyType& key) const; 69 base::string16 GetString16(const KeyType& key) const;
62 base::string16 GetString16(const KeyType& key, 70 base::string16 GetString16(const KeyType& key,
63 const base::string16& default_value) const; 71 const base::string16& default_value) const;
64 StringList GetStringList(const KeyType& key) const; 72 StringList GetStringList(const KeyType& key) const;
65 StringList GetStringList(const KeyType& key, 73 StringList GetStringList(const KeyType& key,
66 const StringList& default_value) const; 74 const StringList& default_value) const;
67 String16List GetString16List(const KeyType& key) const; 75 String16List GetString16List(const KeyType& key) const;
68 String16List GetString16List(const KeyType& key, 76 String16List GetString16List(const KeyType& key,
69 const String16List& default_value) const; 77 const String16List& default_value) const;
70 78
79 scoped_ptr<KeyObserverSubscription> AddKeyObserver(
80 const KeyType& key,
81 const KeyObserver& observer);
82
71 // Returns true if context has |key|. 83 // Returns true if context has |key|.
72 bool HasKey(const KeyType& key) const; 84 bool HasKey(const KeyType& key) const;
73 85
74 // Returns true if there was changes since last call to 86 // Returns true if there was changes since last call to
75 // GetChangesAndReset(). 87 // GetChangesAndReset().
76 bool HasChanges() const; 88 bool HasChanges() const;
77 89
78 // Stores all changes since the last call to the 90 // Stores all changes since the last call to the
79 // GetChangesAndReset() in |diff|. All previous contents of |diff| 91 // GetChangesAndReset() in |diff|. All previous contents of |diff|
80 // will be thrown away. 92 // will be thrown away.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return default_value; 124 return default_value;
113 return Get<T>(key); 125 return Get<T>(key);
114 } 126 }
115 127
116 // Contains current state of <key, value> map. 128 // Contains current state of <key, value> map.
117 base::DictionaryValue storage_; 129 base::DictionaryValue storage_;
118 130
119 // Contains all pending changes. 131 // Contains all pending changes.
120 base::DictionaryValue changes_; 132 base::DictionaryValue changes_;
121 133
134 base::hash_map<KeyType, linked_ptr<KeyObserversList>> key_observers_;
135
122 DISALLOW_COPY_AND_ASSIGN(ScreenContext); 136 DISALLOW_COPY_AND_ASSIGN(ScreenContext);
123 }; 137 };
124 138
125 } // namespace login 139 } // namespace login
126 140
127 #endif // COMPONENTS_LOGIN_SCREENS_SCREEN_CONTEXT_H_ 141 #endif // COMPONENTS_LOGIN_SCREENS_SCREEN_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698