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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_whitelist_service.cc

Issue 1408023003: Don't persist registrations for whitelists installed from the command line. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 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
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_whitelist_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" 5 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 std::string id; 77 std::string id;
78 std::string name; 78 std::string name;
79 size_t separator = whitelist.find(':'); 79 size_t separator = whitelist.find(':');
80 if (separator != base::StringPiece::npos) { 80 if (separator != base::StringPiece::npos) {
81 whitelist.substr(0, separator).CopyToString(&id); 81 whitelist.substr(0, separator).CopyToString(&id);
82 whitelist.substr(separator + 1).CopyToString(&name); 82 whitelist.substr(separator + 1).CopyToString(&name);
83 } else { 83 } else {
84 whitelist.CopyToString(&id); 84 whitelist.CopyToString(&id);
85 } 85 }
86 86
87 // Skip whitelists that were already registered. 87 RegisterWhitelist(id, name, FROM_COMMAND_LINE);
88 if (registered_whitelists_.count(id) > 0u)
89 continue;
90
91 bool new_installation = true;
92 RegisterWhitelist(id, name, new_installation);
93 } 88 }
94 } 89 }
95 90
96 void SupervisedUserWhitelistService::AddSiteListsChangedCallback( 91 void SupervisedUserWhitelistService::AddSiteListsChangedCallback(
97 const SiteListsChangedCallback& callback) { 92 const SiteListsChangedCallback& callback) {
98 site_lists_changed_callbacks_.push_back(callback); 93 site_lists_changed_callbacks_.push_back(callback);
99 94
100 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; 95 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists;
101 GetLoadedWhitelists(&whitelists); 96 GetLoadedWhitelists(&whitelists);
102 callback.Run(whitelists); 97 callback.Run(whitelists);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 NotifyWhitelistsChanged(); 257 NotifyWhitelistsChanged();
263 258
264 return error; 259 return error;
265 } 260 }
266 261
267 void SupervisedUserWhitelistService::AddNewWhitelist( 262 void SupervisedUserWhitelistService::AddNewWhitelist(
268 base::DictionaryValue* pref_dict, 263 base::DictionaryValue* pref_dict,
269 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { 264 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) {
270 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Added")); 265 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Added"));
271 266
272 bool new_installation = true; 267 RegisterWhitelist(whitelist.id(), whitelist.name(), FROM_SYNC);
273 RegisterWhitelist(whitelist.id(), whitelist.name(), new_installation);
274 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 268 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
275 SetWhitelistProperties(dict.get(), whitelist); 269 SetWhitelistProperties(dict.get(), whitelist);
276 pref_dict->SetWithoutPathExpansion(whitelist.id(), dict.release()); 270 pref_dict->SetWithoutPathExpansion(whitelist.id(), dict.release());
277 } 271 }
278 272
279 void SupervisedUserWhitelistService::SetWhitelistProperties( 273 void SupervisedUserWhitelistService::SetWhitelistProperties(
280 base::DictionaryValue* dict, 274 base::DictionaryValue* dict,
281 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) { 275 const sync_pb::ManagedUserWhitelistSpecifics& whitelist) {
282 dict->SetString(kName, whitelist.name()); 276 dict->SetString(kName, whitelist.name());
283 } 277 }
284 278
285 void SupervisedUserWhitelistService::RemoveWhitelist( 279 void SupervisedUserWhitelistService::RemoveWhitelist(
286 base::DictionaryValue* pref_dict, 280 base::DictionaryValue* pref_dict,
287 const std::string& id) { 281 const std::string& id) {
288 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Removed")); 282 base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Removed"));
289 283
290 pref_dict->RemoveWithoutPathExpansion(id, NULL); 284 pref_dict->RemoveWithoutPathExpansion(id, NULL);
291 installer_->UnregisterWhitelist(client_id_, id); 285 installer_->UnregisterWhitelist(client_id_, id);
292 UnloadWhitelist(id); 286 UnloadWhitelist(id);
293 } 287 }
294 288
295 void SupervisedUserWhitelistService::RegisterWhitelist(const std::string& id, 289 void SupervisedUserWhitelistService::RegisterWhitelist(const std::string& id,
296 const std::string& name, 290 const std::string& name,
297 bool new_installation) { 291 WhitelistSource source) {
298 bool result = registered_whitelists_.insert(id).second; 292 bool result = registered_whitelists_.insert(id).second;
299 DCHECK(result); 293 DCHECK(result);
300 294
301 installer_->RegisterWhitelist(client_id_, id, name); 295 // Using an empty client ID for whitelists installed from the command line
296 // causes the installer to not persist the installation, so the whitelist will
297 // be removed the next time the browser is started without the command line
298 // flag.
299 installer_->RegisterWhitelist(
300 source == FROM_COMMAND_LINE ? std::string() : client_id_, id, name);
302 } 301 }
303 302
304 void SupervisedUserWhitelistService::GetLoadedWhitelists( 303 void SupervisedUserWhitelistService::GetLoadedWhitelists(
305 std::vector<scoped_refptr<SupervisedUserSiteList>>* whitelists) { 304 std::vector<scoped_refptr<SupervisedUserSiteList>>* whitelists) {
306 for (const auto& whitelist : loaded_whitelists_) 305 for (const auto& whitelist : loaded_whitelists_)
307 whitelists->push_back(whitelist.second); 306 whitelists->push_back(whitelist.second);
308 } 307 }
309 308
310 void SupervisedUserWhitelistService::NotifyWhitelistsChanged() { 309 void SupervisedUserWhitelistService::NotifyWhitelistsChanged() {
311 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists; 310 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists;
(...skipping 29 matching lines...) Expand all
341 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration", 340 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.TotalLoadDuration",
342 base::TimeTicks::Now() - start_time); 341 base::TimeTicks::Now() - start_time);
343 342
344 // If the whitelist has been unregistered in the mean time, ignore it. 343 // If the whitelist has been unregistered in the mean time, ignore it.
345 if (registered_whitelists_.count(id) == 0u) 344 if (registered_whitelists_.count(id) == 0u)
346 return; 345 return;
347 346
348 loaded_whitelists_[id] = whitelist; 347 loaded_whitelists_[id] = whitelist;
349 NotifyWhitelistsChanged(); 348 NotifyWhitelistsChanged();
350 } 349 }
OLDNEW
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_whitelist_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698