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

Side by Side Diff: chrome/browser/sessions/restore_on_startup_policy_handler.cc

Issue 1312693005: Remove migration of obsolete value for "session.restore_on_startup". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url-to-restore-on-startup
Patch Set: Address comments Created 5 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/sessions/restore_on_startup_policy_handler.h" 5 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h"
6 6
7 #include "base/prefs/pref_value_map.h" 7 #include "base/prefs/pref_value_map.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/prefs/session_startup_pref.h" 10 #include "chrome/browser/prefs/session_startup_pref.h"
(...skipping 14 matching lines...) Expand all
25 25
26 void RestoreOnStartupPolicyHandler::ApplyPolicySettings( 26 void RestoreOnStartupPolicyHandler::ApplyPolicySettings(
27 const PolicyMap& policies, 27 const PolicyMap& policies,
28 PrefValueMap* prefs) { 28 PrefValueMap* prefs) {
29 const base::Value* restore_on_startup_value = 29 const base::Value* restore_on_startup_value =
30 policies.GetValue(policy_name()); 30 policies.GetValue(policy_name());
31 if (restore_on_startup_value) { 31 if (restore_on_startup_value) {
32 int restore_on_startup; 32 int restore_on_startup;
33 if (!restore_on_startup_value->GetAsInteger(&restore_on_startup)) 33 if (!restore_on_startup_value->GetAsInteger(&restore_on_startup))
34 return; 34 return;
35 35 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup);
36 if (restore_on_startup == SessionStartupPref::kPrefValueHomePage)
37 ApplyPolicySettingsFromHomePage(policies, prefs);
38 else
39 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup);
40 } 36 }
41 } 37 }
42 38
43 void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage(
44 const PolicyMap& policies,
45 PrefValueMap* prefs) {
46 const base::Value* homepage_is_new_tab_page_value =
47 policies.GetValue(key::kHomepageIsNewTabPage);
48 if (!homepage_is_new_tab_page_value) {
49 // The policy is enforcing 'open the homepage on startup' but not
50 // enforcing what the homepage should be. Don't set any prefs.
51 return;
52 }
53
54 bool homepage_is_new_tab_page;
55 if (!homepage_is_new_tab_page_value->GetAsBoolean(&homepage_is_new_tab_page))
56 return;
57
58 if (homepage_is_new_tab_page) {
59 prefs->SetInteger(prefs::kRestoreOnStartup,
60 SessionStartupPref::kPrefValueNewTab);
61 } else {
62 const base::Value* homepage_value =
63 policies.GetValue(key::kHomepageLocation);
64 if (!homepage_value || !homepage_value->IsType(base::Value::TYPE_STRING)) {
65 // The policy is enforcing 'open the homepage on startup' but not
66 // enforcing what the homepage should be. Don't set any prefs.
67 return;
68 }
69 scoped_ptr<base::ListValue> url_list(new base::ListValue());
70 url_list->Append(homepage_value->CreateDeepCopy());
71 prefs->SetInteger(prefs::kRestoreOnStartup,
72 SessionStartupPref::kPrefValueURLs);
73 prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list.Pass());
74 }
75 }
76
77 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( 39 bool RestoreOnStartupPolicyHandler::CheckPolicySettings(
78 const PolicyMap& policies, 40 const PolicyMap& policies,
79 PolicyErrorMap* errors) { 41 PolicyErrorMap* errors) {
80 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors)) 42 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors))
81 return false; 43 return false;
82 44
83 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); 45 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup);
84 46
85 if (restore_policy) { 47 if (restore_policy) {
86 int restore_value; 48 int restore_value;
87 CHECK(restore_policy->GetAsInteger(&restore_value)); // Passed type check. 49 CHECK(restore_policy->GetAsInteger(&restore_value)); // Passed type check.
88 switch (restore_value) { 50 switch (restore_value) {
89 case SessionStartupPref::kPrefValueHomePage: 51 case 0 /* kPrefValueHomePage */:
gab 2015/12/03 15:28:49 case 0: // Deprecated kPrefValueHomePage. (i.e.
sdefresne 2015/12/03 15:34:13 Done.
90 errors->AddError(policy_name(), IDS_POLICY_VALUE_DEPRECATED); 52 errors->AddError(policy_name(), IDS_POLICY_VALUE_DEPRECATED);
91 break; 53 break;
92 case SessionStartupPref::kPrefValueLast: { 54 case SessionStartupPref::kPrefValueLast: {
93 // If the "restore last session" policy is set, session cookies are 55 // If the "restore last session" policy is set, session cookies are
94 // treated as permanent cookies and site data needed to restore the 56 // treated as permanent cookies and site data needed to restore the
95 // session is not cleared so we have to warn the user in that case. 57 // session is not cleared so we have to warn the user in that case.
96 const base::Value* cookies_policy = 58 const base::Value* cookies_policy =
97 policies.GetValue(key::kCookiesSessionOnlyForUrls); 59 policies.GetValue(key::kCookiesSessionOnlyForUrls);
98 const base::ListValue* cookies_value; 60 const base::ListValue* cookies_value;
99 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && 61 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) &&
(...skipping 21 matching lines...) Expand all
121 default: 83 default:
122 errors->AddError(policy_name(), 84 errors->AddError(policy_name(),
123 IDS_POLICY_OUT_OF_RANGE_ERROR, 85 IDS_POLICY_OUT_OF_RANGE_ERROR,
124 base::IntToString(restore_value)); 86 base::IntToString(restore_value));
125 } 87 }
126 } 88 }
127 return true; 89 return true;
128 } 90 }
129 91
130 } // namespace policy 92 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698