OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/session_startup_pref.h" | 5 #include "chrome/browser/session_startup_pref.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/defaults.h" | 10 #include "chrome/browser/defaults.h" |
11 #include "chrome/browser/pref_service.h" | 11 #include "chrome/browser/pref_service.h" |
12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/scoped_pref_update.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // For historical reasons the enum and value registered in the prefs don't line | 18 // For historical reasons the enum and value registered in the prefs don't line |
18 // up. These are the values registered in prefs. | 19 // up. These are the values registered in prefs. |
19 const int kPrefValueDefault = 0; | 20 const int kPrefValueDefault = 0; |
20 const int kPrefValueLast = 1; | 21 const int kPrefValueLast = 1; |
21 const int kPrefValueURLs = 4; | 22 const int kPrefValueURLs = 4; |
22 | 23 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 // static | 59 // static |
59 void SessionStartupPref::SetStartupPref(PrefService* prefs, | 60 void SessionStartupPref::SetStartupPref(PrefService* prefs, |
60 const SessionStartupPref& pref) { | 61 const SessionStartupPref& pref) { |
61 DCHECK(prefs); | 62 DCHECK(prefs); |
62 prefs->SetInteger(prefs::kRestoreOnStartup, TypeToPrefValue(pref.type)); | 63 prefs->SetInteger(prefs::kRestoreOnStartup, TypeToPrefValue(pref.type)); |
63 | 64 |
64 // Always save the URLs, that way the UI can remain consistent even if the | 65 // Always save the URLs, that way the UI can remain consistent even if the |
65 // user changes the startup type pref. | 66 // user changes the startup type pref. |
66 // Ownership of the ListValue retains with the pref service. | 67 // Ownership of the ListValue retains with the pref service. |
| 68 ScopedPrefUpdate update(prefs, prefs::kURLsToRestoreOnStartup); |
67 ListValue* url_pref_list = | 69 ListValue* url_pref_list = |
68 prefs->GetMutableList(prefs::kURLsToRestoreOnStartup); | 70 prefs->GetMutableList(prefs::kURLsToRestoreOnStartup); |
69 DCHECK(url_pref_list); | 71 DCHECK(url_pref_list); |
70 url_pref_list->Clear(); | 72 url_pref_list->Clear(); |
71 for (size_t i = 0; i < pref.urls.size(); ++i) { | 73 for (size_t i = 0; i < pref.urls.size(); ++i) { |
72 url_pref_list->Set(static_cast<int>(i), | 74 url_pref_list->Set(static_cast<int>(i), |
73 new StringValue(UTF8ToWide(pref.urls[i].spec()))); | 75 new StringValue(UTF8ToWide(pref.urls[i].spec()))); |
74 } | 76 } |
75 } | 77 } |
76 | 78 |
(...skipping 18 matching lines...) Expand all Loading... |
95 Value* value = NULL; | 97 Value* value = NULL; |
96 if (url_pref_list->Get(i, &value)) { | 98 if (url_pref_list->Get(i, &value)) { |
97 std::string url_text; | 99 std::string url_text; |
98 if (value->GetAsString(&url_text)) | 100 if (value->GetAsString(&url_text)) |
99 pref.urls.push_back(GURL(url_text)); | 101 pref.urls.push_back(GURL(url_text)); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 return pref; | 105 return pref; |
104 } | 106 } |
OLD | NEW |