OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/protector/protected_prefs_watcher.h" | 5 #include "chrome/browser/protector/protected_prefs_watcher.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 std::string value; | 56 std::string value; |
57 if (!it.value().GetAsString(&value)) | 57 if (!it.value().GetAsString(&value)) |
58 NOTREACHED(); | 58 NOTREACHED(); |
59 base::StringAppendF(out, "|%s|%s", it.key().c_str(), value.c_str()); | 59 base::StringAppendF(out, "|%s|%s", it.key().c_str(), value.c_str()); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 // static | 65 // static |
66 const int ProtectedPrefsWatcher::kCurrentVersionNumber = 2; | 66 const int ProtectedPrefsWatcher::kCurrentVersionNumber = 3; |
67 | 67 |
68 ProtectedPrefsWatcher::ProtectedPrefsWatcher(Profile* profile) | 68 ProtectedPrefsWatcher::ProtectedPrefsWatcher(Profile* profile) |
69 : is_backup_valid_(true), | 69 : is_backup_valid_(true), |
70 profile_(profile) { | 70 profile_(profile) { |
71 // Perform necessary pref migrations before actually starting to observe | 71 // Perform necessary pref migrations before actually starting to observe |
72 // pref changes, otherwise the migration would affect the backup data as well. | 72 // pref changes, otherwise the migration would affect the backup data as well. |
73 EnsurePrefsMigration(); | 73 EnsurePrefsMigration(); |
74 pref_observer_.reset(PrefSetObserver::CreateProtectedPrefSetObserver( | 74 pref_observer_.reset(PrefSetObserver::CreateProtectedPrefSetObserver( |
75 profile->GetPrefs(), this)); | 75 profile->GetPrefs(), this)); |
76 UpdateCachedPrefs(); | 76 UpdateCachedPrefs(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 void ProtectedPrefsWatcher::MigrateOldBackupIfNeeded() { | 201 void ProtectedPrefsWatcher::MigrateOldBackupIfNeeded() { |
202 PrefService* prefs = profile_->GetPrefs(); | 202 PrefService* prefs = profile_->GetPrefs(); |
203 | 203 |
204 int current_version = prefs->GetInteger(kBackupVersion); | 204 int current_version = prefs->GetInteger(kBackupVersion); |
205 VLOG(1) << "Backup version: " << current_version; | 205 VLOG(1) << "Backup version: " << current_version; |
206 if (current_version == kCurrentVersionNumber) | 206 if (current_version == kCurrentVersionNumber) |
207 return; | 207 return; |
208 | 208 |
209 switch (current_version) { | 209 switch (current_version) { |
210 case 1: | 210 case 1: |
| 211 // Add pinned tabs. |
211 prefs->Set(kBackupPinnedTabs, *prefs->GetList(prefs::kPinnedTabs)); | 212 prefs->Set(kBackupPinnedTabs, *prefs->GetList(prefs::kPinnedTabs)); |
212 // FALL THROUGH | 213 // FALL THROUGH |
| 214 |
| 215 case 2: |
| 216 // SessionStartupPref migration. |
| 217 DCHECK(prefs->GetBoolean(prefs::kRestoreOnStartupMigrated)); |
| 218 prefs->SetInteger(kBackupRestoreOnStartup, |
| 219 prefs->GetInteger(prefs::kRestoreOnStartup)); |
| 220 prefs->Set(kBackupURLsToRestoreOnStartup, |
| 221 *prefs->GetList(prefs::kURLsToRestoreOnStartup)); |
| 222 // FALL THROUGH |
213 } | 223 } |
214 | 224 |
215 prefs->SetInteger(kBackupVersion, kCurrentVersionNumber); | 225 prefs->SetInteger(kBackupVersion, kCurrentVersionNumber); |
216 UpdateBackupSignature(); | 226 UpdateBackupSignature(); |
217 } | 227 } |
218 | 228 |
219 bool ProtectedPrefsWatcher::UpdateBackupEntry(const std::string& pref_name) { | 229 bool ProtectedPrefsWatcher::UpdateBackupEntry(const std::string& pref_name) { |
220 PrefService* prefs = profile_->GetPrefs(); | 230 PrefService* prefs = profile_->GetPrefs(); |
221 if (pref_name == ExtensionPrefs::kExtensionsPref) { | 231 if (pref_name == ExtensionPrefs::kExtensionsPref) { |
222 // For changes in extension dictionary, do nothing if the IDs list remained | 232 // For changes in extension dictionary, do nothing if the IDs list remained |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 NOTREACHED(); | 341 NOTREACHED(); |
332 continue; | 342 continue; |
333 } | 343 } |
334 StringAppendStringDictionary(tab, &data); | 344 StringAppendStringDictionary(tab, &data); |
335 } | 345 } |
336 } | 346 } |
337 return data; | 347 return data; |
338 } | 348 } |
339 | 349 |
340 } // namespace protector | 350 } // namespace protector |
OLD | NEW |