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

Side by Side Diff: chrome/browser/chromeos/user_cros_settings_provider.cc

Issue 7741045: Delay the metrics policy migration call to make sure ownership has been taken. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments. Created 9 years, 3 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/chromeos/login/signed_settings.cc ('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 (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 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 5 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/cros/login_library.h" 20 #include "chrome/browser/chromeos/cros/login_library.h"
21 #include "chrome/browser/chromeos/cros/network_library.h" 21 #include "chrome/browser/chromeos/cros/network_library.h"
22 #include "chrome/browser/chromeos/cros_settings.h" 22 #include "chrome/browser/chromeos/cros_settings.h"
23 #include "chrome/browser/chromeos/cros_settings_names.h" 23 #include "chrome/browser/chromeos/cros_settings_names.h"
24 #include "chrome/browser/chromeos/login/ownership_service.h" 24 #include "chrome/browser/chromeos/login/ownership_service.h"
25 #include "chrome/browser/chromeos/login/user_manager.h" 25 #include "chrome/browser/chromeos/login/user_manager.h"
26 #include "chrome/browser/policy/browser_policy_connector.h" 26 #include "chrome/browser/policy/browser_policy_connector.h"
27 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/prefs/scoped_user_pref_update.h" 28 #include "chrome/browser/prefs/scoped_user_pref_update.h"
29 #include "chrome/browser/ui/options/options_util.h" 29 #include "chrome/browser/ui/options/options_util.h"
30 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/installer/util/google_update_settings.h" 31 #include "chrome/installer/util/google_update_settings.h"
31 #include "content/browser/browser_thread.h" 32 #include "content/browser/browser_thread.h"
32 33
33 namespace chromeos { 34 namespace chromeos {
34 35
35 namespace { 36 namespace {
36 37
37 const char kTrueIncantation[] = "true"; 38 const char kTrueIncantation[] = "true";
38 const char kFalseIncantation[] = "false"; 39 const char kFalseIncantation[] = "false";
39 const char kTrustedSuffix[] = "/trusted"; 40 const char kTrustedSuffix[] = "/trusted";
(...skipping 11 matching lines...) Expand all
51 52
52 const char* kStringSettings[] = { 53 const char* kStringSettings[] = {
53 kDeviceOwner, 54 kDeviceOwner,
54 kReleaseChannel 55 kReleaseChannel
55 }; 56 };
56 57
57 const char* kListSettings[] = { 58 const char* kListSettings[] = {
58 kAccountsPrefUsers 59 kAccountsPrefUsers
59 }; 60 };
60 61
61 // Only write the property if the owner is the current logged on user. 62 // This class provides the means to migrate settings to the signed settings
62 void StartStorePropertyOpIfOwner(const std::string& name, 63 // store. It does one of three things - stored the settings in the policy blob
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 s/stored/store/
pastarmovj 2011/08/31 14:29:36 Done.
63 const std::string& value, 64 // immediately if the current user is the owner. Uses the
64 SignedSettingsHelper::Callback* callback) { 65 // SignedSettingsTempStorage if there is no owner yet, or waits for an
65 if (OwnershipService::GetSharedInstance()->CurrentUserIsOwner()) { 66 // OWNERSHIP_CHECKED notification to delay the storing until the owner has
66 BrowserThread::PostTask(BrowserThread::UI, 67 // logged in.
67 FROM_HERE, 68 class MigrationHelper : public NotificationObserver {
68 base::Bind( 69 public:
69 &SignedSettingsHelper::StartStorePropertyOp, 70 explicit MigrationHelper() : callback_(NULL) {
70 base::Unretained(SignedSettingsHelper::Get()), 71 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED,
71 name, 72 NotificationService::AllSources());
72 value,
73 callback));
74 } 73 }
75 } 74
75 void set_callback(SignedSettingsHelper::Callback* callback) {
76 callback_ = callback;
77 }
78
79 void AddMigrationValue(const std::string& path, const std::string& value) {
80 // Migration value is not thread safe so take care if you call this function
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 what is not thread safe? Isn't it the case that yo
pastarmovj 2011/08/31 14:29:36 This comment is obsolete now that we don't have to
81 // while MigrateValues is running. You can make sure this is not the case if
82 // You only call this function on the FILE thread.
83 migration_values_[path] = value;
84 }
85
86 void MigrateValues(void) {
87 // The check we do below should be done on the file thread so if we are not
88 // there jump on the right thread.
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 s/jump on/jump to/
pastarmovj 2011/08/31 14:29:36 Done.
89 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
90 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
91 base::Bind(&MigrationHelper::MigrateValues,
92 base::Unretained(this)));
93 return;
94 }
95
96 OwnershipService* service = OwnershipService::GetSharedInstance();
97 if (service->CurrentUserIsOwner() ||
98 service->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) {
99 std::map<std::string, std::string>::const_iterator i =
100 migration_values_.begin();
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 maybe move the i = migration_values_.begin() into
pastarmovj 2011/08/31 14:29:36 Done.
101 for (; i != migration_values_.end(); ++i) {
102 // This is needed to avoid loosing the value after the clear below.
103 // Temp objects passed by const ref will have the life time of the ref.
104 const std::string name = i->first;
105 const std::string value = i->second;
106 // Queue all values for storing.
107 BrowserThread::PostTask(
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 It seems like you should only do the ownership che
pastarmovj 2011/08/31 14:29:36 Tuned the OwnershipStatusChecker to supply all the
108 BrowserThread::UI, FROM_HERE,
109 base::Bind(
110 &SignedSettingsHelper::StartStorePropertyOp,
111 base::Unretained(SignedSettingsHelper::Get()),
112 name, value,
113 callback_));
114 }
115 migration_values_.clear();
116 } else {
117 // Either we are not yet logged in or the user currently logged in is not
118 // the owner. So we should wait for user change. (Actually only the first
119 // case is interesting for us.)
120 }
121 }
122
123 // NotificationObserver overrides:
124 virtual void Observe(int type,
125 const NotificationSource& source,
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 indentation.
pastarmovj 2011/08/31 14:29:36 Done.
126 const NotificationDetails& details) OVERRIDE {
127 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED) {
128 if (!migration_values_.empty())
Mattias Nissler (ping if slow) 2011/08/31 12:47:24 it's not safe to check from the UI thread, just do
pastarmovj 2011/08/31 14:29:36 Done.
129 MigrateValues();
130 }
131 }
132
133 private:
134 NotificationRegistrar registrar_;
135 std::map<std::string, std::string> migration_values_;
136 SignedSettingsHelper::Callback* callback_;
137
138 DISALLOW_COPY_AND_ASSIGN(MigrationHelper);
139 };
76 140
77 bool IsControlledBooleanSetting(const std::string& pref_path) { 141 bool IsControlledBooleanSetting(const std::string& pref_path) {
78 // TODO(nkostylev): Using std::find for 4 value array generates this warning 142 // TODO(nkostylev): Using std::find for 4 value array generates this warning
79 // in chroot stl_algo.h:231: error: array subscript is above array bounds. 143 // in chroot stl_algo.h:231: error: array subscript is above array bounds.
80 // GCC 4.4.3 144 // GCC 4.4.3
81 return (pref_path == kAccountsPrefAllowNewUser) || 145 return (pref_path == kAccountsPrefAllowNewUser) ||
82 (pref_path == kAccountsPrefAllowGuest) || 146 (pref_path == kAccountsPrefAllowGuest) ||
83 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || 147 (pref_path == kAccountsPrefShowUserNamesOnSignIn) ||
84 (pref_path == kSignedDataRoamingEnabled) || 148 (pref_path == kSignedDataRoamingEnabled) ||
85 (pref_path == kStatsReportingPref); 149 (pref_path == kStatsReportingPref);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 346 }
283 } 347 }
284 348
285 private: 349 private:
286 // upper bound for number of retries to fetch a signed setting. 350 // upper bound for number of retries to fetch a signed setting.
287 static const int kNumRetriesLimit = 9; 351 static const int kNumRetriesLimit = 9;
288 352
289 UserCrosSettingsTrust() 353 UserCrosSettingsTrust()
290 : ownership_service_(OwnershipService::GetSharedInstance()), 354 : ownership_service_(OwnershipService::GetSharedInstance()),
291 retries_left_(kNumRetriesLimit) { 355 retries_left_(kNumRetriesLimit) {
356 migration_helper_.set_callback(this);
292 // Start prefetching Boolean and String preferences. 357 // Start prefetching Boolean and String preferences.
293 Reload(); 358 Reload();
294 } 359 }
295 360
296 virtual ~UserCrosSettingsTrust() { 361 virtual ~UserCrosSettingsTrust() {
297 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && 362 if (BrowserThread::CurrentlyOn(BrowserThread::UI) &&
298 CrosLibrary::Get()->EnsureLoaded()) { 363 CrosLibrary::Get()->EnsureLoaded()) {
299 // Cancels all pending callbacks from us. 364 // Cancels all pending callbacks from us.
300 SignedSettingsHelper::Get()->CancelCallback(this); 365 SignedSettingsHelper::Get()->CancelCallback(this);
301 } 366 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 410 }
346 } else if (path == kStatsReportingPref) { 411 } else if (path == kStatsReportingPref) {
347 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; 412 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false;
348 // TODO(pastarmovj): Remove this once migration is not needed anymore. 413 // TODO(pastarmovj): Remove this once migration is not needed anymore.
349 // If the value is not set we should try to migrate legacy consent file. 414 // If the value is not set we should try to migrate legacy consent file.
350 if (use_value == USE_VALUE_DEFAULT) { 415 if (use_value == USE_VALUE_DEFAULT) {
351 // Loading consent file state causes us to do blocking IO on UI thread. 416 // Loading consent file state causes us to do blocking IO on UI thread.
352 // Temporarily allow it until we fix http://crbug.com/62626 417 // Temporarily allow it until we fix http://crbug.com/62626
353 base::ThreadRestrictions::ScopedAllowIO allow_io; 418 base::ThreadRestrictions::ScopedAllowIO allow_io;
354 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); 419 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent();
355 // Only store settings if the owner is logged on, otherwise the write 420 // Make sure the values will get eventually written to the policy file.
356 // will fail, triggering another read and we'll end up in an infinite 421 migration_helper_.AddMigrationValue(
357 // loop. Owner check needs to be done on the FILE thread. 422 path, stats_consent ? "true" : "false");
358 BrowserThread::PostTask(BrowserThread::FILE, 423 migration_helper_.MigrateValues();
359 FROM_HERE,
360 base::Bind(&StartStorePropertyOpIfOwner, path,
361 stats_consent ? "true" : "false",
362 this));
363 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); 424 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED);
364 LOG(WARNING) << "No metrics policy set will revert to checking " 425 LOG(WARNING) << "No metrics policy set will revert to checking "
365 << "consent file which is " 426 << "consent file which is "
366 << (stats_consent ? "on." : "off."); 427 << (stats_consent ? "on." : "off.");
367 } 428 }
368 // TODO(pastarmovj): Remove this once we don't need to regenerate the 429 // TODO(pastarmovj): Remove this once we don't need to regenerate the
369 // consent file for the GUID anymore. 430 // consent file for the GUID anymore.
370 VLOG(1) << "Metrics policy is being set to : " << stats_consent 431 VLOG(1) << "Metrics policy is being set to : " << stats_consent
371 << "(reason : " << use_value << ")"; 432 << "(reason : " << use_value << ")";
372 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); 433 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 545
485 // Reload the whitelist on settings op failure. 546 // Reload the whitelist on settings op failure.
486 if (code != SignedSettings::SUCCESS) 547 if (code != SignedSettings::SUCCESS)
487 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); 548 CrosSettings::Get()->FireObservers(kAccountsPrefUsers);
488 } 549 }
489 550
490 // Pending callbacks that need to be invoked after settings verification. 551 // Pending callbacks that need to be invoked after settings verification.
491 base::hash_map< std::string, std::vector< Task* > > callbacks_; 552 base::hash_map< std::string, std::vector< Task* > > callbacks_;
492 553
493 OwnershipService* ownership_service_; 554 OwnershipService* ownership_service_;
555 MigrationHelper migration_helper_;
494 556
495 // In order to guard against occasional failure to fetch a property 557 // In order to guard against occasional failure to fetch a property
496 // we allow for some number of retries. 558 // we allow for some number of retries.
497 int retries_left_; 559 int retries_left_;
498 560
499 friend class SignedSettingsHelper; 561 friend class SignedSettingsHelper;
500 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; 562 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>;
501 563
502 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); 564 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust);
503 }; 565 };
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 if (cached_whitelist_update->Remove(email_value, NULL)) 760 if (cached_whitelist_update->Remove(email_value, NULL))
699 prefs->ScheduleSavePersistentPrefs(); 761 prefs->ScheduleSavePersistentPrefs();
700 } 762 }
701 763
702 // static 764 // static
703 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { 765 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) {
704 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); 766 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED);
705 } 767 }
706 768
707 } // namespace chromeos 769 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/signed_settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698