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

Side by Side Diff: chrome/browser/prefs/pref_model_associator.h

Issue 7259019: Move base/values.h into the base namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
« no previous file with comments | « chrome/browser/prefs/pref_member.h ('k') | chrome/browser/prefs/pref_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ 5 #ifndef CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_
6 #define CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ 6 #define CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/sync/api/syncable_service.h" 17 #include "chrome/browser/sync/api/syncable_service.h"
18 #include "chrome/browser/sync/api/sync_data.h" 18 #include "chrome/browser/sync/api/sync_data.h"
19 19
20 namespace sync_pb { 20 namespace sync_pb {
21 class PreferenceSpecifics; 21 class PreferenceSpecifics;
22 } 22 }
23 23
24 namespace base {
24 class Value; 25 class Value;
26 }
25 27
26 // Contains all preference sync related logic. 28 // Contains all preference sync related logic.
27 // TODO(sync): Merge this into PrefService once we separate the profile 29 // TODO(sync): Merge this into PrefService once we separate the profile
28 // PrefService from the local state PrefService. 30 // PrefService from the local state PrefService.
29 class PrefModelAssociator 31 class PrefModelAssociator
30 : public SyncableService, 32 : public SyncableService,
31 public base::NonThreadSafe { 33 public base::NonThreadSafe {
32 public: 34 public:
33 explicit PrefModelAssociator(PrefService* pref_service); 35 explicit PrefModelAssociator(PrefService* pref_service);
34 virtual ~PrefModelAssociator(); 36 virtual ~PrefModelAssociator();
(...skipping 24 matching lines...) Expand all
59 61
60 // Process a local preference change. This can trigger new SyncChanges being 62 // Process a local preference change. This can trigger new SyncChanges being
61 // sent to the syncer. 63 // sent to the syncer.
62 virtual void ProcessPrefChange(const std::string& name); 64 virtual void ProcessPrefChange(const std::string& name);
63 65
64 // Merges the value of local_pref into the supplied server_value and returns 66 // Merges the value of local_pref into the supplied server_value and returns
65 // the result (caller takes ownership). If there is a conflict, the server 67 // the result (caller takes ownership). If there is a conflict, the server
66 // value always takes precedence. Note that only certain preferences will 68 // value always takes precedence. Note that only certain preferences will
67 // actually be merged, all others will return a copy of the server value. See 69 // actually be merged, all others will return a copy of the server value. See
68 // the method's implementation for details. 70 // the method's implementation for details.
69 static Value* MergePreference(const PrefService::Preference& local_pref, 71 static base::Value* MergePreference(
70 const Value& server_value); 72 const PrefService::Preference& local_pref,
73 const base::Value& server_value);
71 74
72 // Fills |sync_data| with a sync representation of the preference data 75 // Fills |sync_data| with a sync representation of the preference data
73 // provided. 76 // provided.
74 static bool CreatePrefSyncData(const std::string& name, 77 static bool CreatePrefSyncData(const std::string& name,
75 const Value& value, 78 const base::Value& value,
76 SyncData* sync_data); 79 SyncData* sync_data);
77 80
78 // Extract preference value and name from sync specifics. 81 // Extract preference value and name from sync specifics.
79 Value* ReadPreferenceSpecifics( 82 base::Value* ReadPreferenceSpecifics(
80 const sync_pb::PreferenceSpecifics& specifics, 83 const sync_pb::PreferenceSpecifics& specifics,
81 std::string* name); 84 std::string* name);
82 85
83 protected: 86 protected:
84 friend class ProfileSyncServicePreferenceTest; 87 friend class ProfileSyncServicePreferenceTest;
85 88
86 typedef std::map<std::string, SyncData> SyncDataMap; 89 typedef std::map<std::string, SyncData> SyncDataMap;
87 90
88 // For testing. 91 // For testing.
89 PrefModelAssociator(); 92 PrefModelAssociator();
90 93
91 // Create an association for a given preference. If |sync_pref| is valid, 94 // Create an association for a given preference. If |sync_pref| is valid,
92 // signifying that sync has data for this preference, we reconcile their data 95 // signifying that sync has data for this preference, we reconcile their data
93 // with ours and append a new UPDATE SyncChange to |sync_changes|. If 96 // with ours and append a new UPDATE SyncChange to |sync_changes|. If
94 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with 97 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with
95 // the current preference data. 98 // the current preference data.
96 // Note: We do not modify the sync data for preferences that are either 99 // Note: We do not modify the sync data for preferences that are either
97 // controlled by policy (are not user modifiable) or have their default value 100 // controlled by policy (are not user modifiable) or have their default value
98 // (are not user controlled). 101 // (are not user controlled).
99 void InitPrefAndAssociate(const SyncData& sync_pref, 102 void InitPrefAndAssociate(const SyncData& sync_pref,
100 const std::string& pref_name, 103 const std::string& pref_name,
101 SyncChangeList* sync_changes); 104 SyncChangeList* sync_changes);
102 105
103 // Perform any additional local operations that need to happen after a 106 // Perform any additional local operations that need to happen after a
104 // preference has been updated. 107 // preference has been updated.
105 void SendUpdateNotificationsIfNecessary(const std::string& pref_name); 108 void SendUpdateNotificationsIfNecessary(const std::string& pref_name);
106 109
107 static Value* MergeListValues(const Value& from_value, const Value& to_value); 110 static base::Value* MergeListValues(
108 static Value* MergeDictionaryValues(const Value& from_value, 111 const base::Value& from_value, const base::Value& to_value);
109 const Value& to_value); 112 static base::Value* MergeDictionaryValues(const base::Value& from_value,
113 const base::Value& to_value);
110 114
111 // Do we have an active association between the preferences and sync models? 115 // Do we have an active association between the preferences and sync models?
112 // Set when start syncing, reset in StopSyncing. While this is not set, we 116 // Set when start syncing, reset in StopSyncing. While this is not set, we
113 // ignore any local preference changes (when we start syncing we will look 117 // ignore any local preference changes (when we start syncing we will look
114 // up the most recent values anyways). 118 // up the most recent values anyways).
115 bool models_associated_; 119 bool models_associated_;
116 120
117 // Whether we're currently processing changes from the syncer. While this is 121 // Whether we're currently processing changes from the syncer. While this is
118 // true, we ignore any local preference changes, since we triggered them. 122 // true, we ignore any local preference changes, since we triggered them.
119 bool processing_syncer_changes_; 123 bool processing_syncer_changes_;
(...skipping 16 matching lines...) Expand all
136 // The PrefService we are syncing to. 140 // The PrefService we are syncing to.
137 PrefService* pref_service_; 141 PrefService* pref_service_;
138 142
139 // Sync's SyncChange handler. We push all our changes through this. 143 // Sync's SyncChange handler. We push all our changes through this.
140 SyncChangeProcessor* sync_processor_; 144 SyncChangeProcessor* sync_processor_;
141 145
142 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); 146 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator);
143 }; 147 };
144 148
145 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ 149 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_member.h ('k') | chrome/browser/prefs/pref_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698