Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Implementation of the Chrome Extensions Managed Mode API. | |
| 6 | |
| 7 #include "chrome/browser/extensions/extension_managed_mode_api.h" | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/extensions/extension_preference_api_constants.h" | |
| 13 #include "chrome/browser/prefs/pref_service.h" | |
|
Bernhard Bauer
2012/03/01 16:32:14
Nit: Remove one empty line here, but add empty lin
| |
| 14 | |
| 15 | |
| 16 namespace { | |
| 17 // Extension-pref key corresponding to the kInManagedMode browser pref. | |
| 18 const char kManagedModeEnabledKey[] = "managedModeEnabled"; | |
| 19 | |
| 20 // Key to report whether the attempt to enable managed mode succeeded. | |
| 21 const char kEnableSuccessKey[] = "success"; | |
| 22 } // namespace | |
| 23 | |
| 24 namespace keys = extension_preference_api_constants; | |
| 25 | |
| 26 GetManagedModeFunction::~GetManagedModeFunction() { } | |
| 27 | |
| 28 bool GetManagedModeFunction::RunImpl() { | |
| 29 std::string browser_pref; | |
| 30 if (!ValidateBrowserPref(kManagedModeEnabledKey, &browser_pref)) | |
|
Bernhard Bauer
2012/03/01 16:32:14
What does it mean when this check fails? The key i
| |
| 31 return false; | |
| 32 PrefService* local_state = g_browser_process->local_state(); | |
| 33 bool enabled = local_state->GetBoolean(browser_pref.c_str()); | |
|
Bernhard Bauer
2012/03/01 16:32:14
Hm, thinking about it, we could directly use the p
| |
| 34 | |
| 35 // Since only one managed-mode extension can be active at a time, this | |
| 36 // extension can control the value iff it is not currently enabled. | |
| 37 // (This will need to be fixed if we ever have a policy or command-line | |
| 38 // switch to prohibit managed mode.) | |
| 39 std::string level_of_control = enabled ? keys::kNotControllable | |
|
Bernhard Bauer
2012/03/01 16:32:14
I'm not sure if this makes anything clearer to the
Pam (message me for reviews)
2012/03/01 20:47:34
My goal was to keep the get() method as close to t
Bernhard Bauer
2012/03/02 09:23:58
OK. We still might to think about what controllabl
| |
| 40 : keys::kControllableByThisExtension; | |
| 41 | |
| 42 scoped_ptr<DictionaryValue> result(new DictionaryValue); | |
| 43 result->SetBoolean(keys::kValue, enabled); | |
| 44 result->SetString(keys::kLevelOfControl, level_of_control); | |
| 45 result_.reset(result.release()); | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 EnableManagedModeFunction::~EnableManagedModeFunction() { } | |
| 50 | |
| 51 bool EnableManagedModeFunction::RunImpl() { | |
| 52 std::string browser_pref; | |
| 53 if (!ValidateBrowserPref(kManagedModeEnabledKey, &browser_pref)) | |
| 54 return false; | |
| 55 PrefService* local_state = g_browser_process->local_state(); | |
| 56 bool enabled = local_state->GetBoolean(browser_pref.c_str()); | |
| 57 | |
| 58 bool confirmed = true; | |
| 59 if (!enabled) { | |
| 60 // TODO(pamg): WIP. Show modal password dialog and save hashed password. Set | |
| 61 // callback_result to false if user cancels dialog. | |
| 62 | |
| 63 if (confirmed) | |
| 64 local_state->SetBoolean(browser_pref.c_str(), true); | |
| 65 } | |
| 66 | |
| 67 scoped_ptr<DictionaryValue> result(new DictionaryValue); | |
| 68 result->SetBoolean(kEnableSuccessKey, confirmed); | |
| 69 result_.reset(result.release()); | |
| 70 return true; | |
| 71 } | |
| OLD | NEW |