| 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/prefs/session_startup_pref.h" | 5 #include "chrome/browser/prefs/session_startup_pref.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| 11 #include "chrome/browser/net/url_fixer_upper.h" | 11 #include "chrome/browser/net/url_fixer_upper.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 13 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/protector/protected_prefs_watcher.h" | |
| 16 #include "chrome/browser/protector/protector_service.h" | |
| 17 #include "chrome/browser/protector/protector_service_factory.h" | |
| 18 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 19 | 16 |
| 20 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
| 21 #include "chrome/browser/ui/cocoa/window_restore_utils.h" | 18 #include "chrome/browser/ui/cocoa/window_restore_utils.h" |
| 22 #endif | 19 #endif |
| 23 | 20 |
| 24 using protector::ProtectedPrefsWatcher; | |
| 25 using protector::ProtectorServiceFactory; | |
| 26 | |
| 27 namespace { | 21 namespace { |
| 28 | 22 |
| 29 // Converts a SessionStartupPref::Type to an integer written to prefs. | 23 // Converts a SessionStartupPref::Type to an integer written to prefs. |
| 30 int TypeToPrefValue(SessionStartupPref::Type type) { | 24 int TypeToPrefValue(SessionStartupPref::Type type) { |
| 31 switch (type) { | 25 switch (type) { |
| 32 case SessionStartupPref::LAST: return SessionStartupPref::kPrefValueLast; | 26 case SessionStartupPref::LAST: return SessionStartupPref::kPrefValueLast; |
| 33 case SessionStartupPref::URLS: return SessionStartupPref::kPrefValueURLs; | 27 case SessionStartupPref::URLS: return SessionStartupPref::kPrefValueURLs; |
| 34 default: return SessionStartupPref::kPrefValueNewTab; | 28 default: return SessionStartupPref::kPrefValueNewTab; |
| 35 } | 29 } |
| 36 } | 30 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // static | 222 // static |
| 229 SessionStartupPref::Type SessionStartupPref::PrefValueToType(int pref_value) { | 223 SessionStartupPref::Type SessionStartupPref::PrefValueToType(int pref_value) { |
| 230 switch (pref_value) { | 224 switch (pref_value) { |
| 231 case kPrefValueLast: return SessionStartupPref::LAST; | 225 case kPrefValueLast: return SessionStartupPref::LAST; |
| 232 case kPrefValueURLs: return SessionStartupPref::URLS; | 226 case kPrefValueURLs: return SessionStartupPref::URLS; |
| 233 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; | 227 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; |
| 234 default: return SessionStartupPref::DEFAULT; | 228 default: return SessionStartupPref::DEFAULT; |
| 235 } | 229 } |
| 236 } | 230 } |
| 237 | 231 |
| 238 // static | |
| 239 bool SessionStartupPref::DidStartupPrefChange(Profile* profile) { | |
| 240 ProtectedPrefsWatcher* prefs_watcher = | |
| 241 ProtectorServiceFactory::GetForProfile(profile)->GetPrefsWatcher(); | |
| 242 return prefs_watcher->DidPrefChange(prefs::kRestoreOnStartup) || | |
| 243 prefs_watcher->DidPrefChange(prefs::kURLsToRestoreOnStartup); | |
| 244 } | |
| 245 | |
| 246 // static | |
| 247 SessionStartupPref SessionStartupPref::GetStartupPrefBackup(Profile* profile) { | |
| 248 protector::ProtectedPrefsWatcher* prefs_watcher = | |
| 249 protector::ProtectorServiceFactory::GetForProfile(profile)-> | |
| 250 GetPrefsWatcher(); | |
| 251 | |
| 252 int type; | |
| 253 CHECK(prefs_watcher->GetBackupForPref( | |
| 254 prefs::kRestoreOnStartup)->GetAsInteger(&type)); | |
| 255 SessionStartupPref backup_pref(PrefValueToType(type)); | |
| 256 | |
| 257 const ListValue* url_list; | |
| 258 CHECK(prefs_watcher->GetBackupForPref( | |
| 259 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list)); | |
| 260 URLListToPref(url_list, &backup_pref); | |
| 261 | |
| 262 return backup_pref; | |
| 263 } | |
| 264 | |
| 265 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} | 232 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} |
| 266 | 233 |
| 267 SessionStartupPref::~SessionStartupPref() {} | 234 SessionStartupPref::~SessionStartupPref() {} |
| OLD | NEW |