OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/power/power_api.h" | 5 #include "extensions/browser/api/power/power_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "device/power_save_blocker/power_save_blocker.h" | 10 #include "device/power_save_blocker/power_save_blocker.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 device::PowerSaveBlocker::Reason reason, | 39 device::PowerSaveBlocker::Reason reason, |
40 const std::string& description, | 40 const std::string& description, |
41 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 41 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
42 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) { | 42 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) { |
43 return std::unique_ptr<device::PowerSaveBlocker>(new device::PowerSaveBlocker( | 43 return std::unique_ptr<device::PowerSaveBlocker>(new device::PowerSaveBlocker( |
44 type, reason, description, ui_task_runner, file_task_runner)); | 44 type, reason, description, ui_task_runner, file_task_runner)); |
45 } | 45 } |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 bool PowerRequestKeepAwakeFunction::RunSync() { | 49 ExtensionFunction::ResponseAction PowerRequestKeepAwakeFunction::Run() { |
50 std::unique_ptr<api::power::RequestKeepAwake::Params> params( | 50 std::unique_ptr<api::power::RequestKeepAwake::Params> params( |
51 api::power::RequestKeepAwake::Params::Create(*args_)); | 51 api::power::RequestKeepAwake::Params::Create(*args_)); |
52 EXTENSION_FUNCTION_VALIDATE(params); | 52 EXTENSION_FUNCTION_VALIDATE(params); |
53 EXTENSION_FUNCTION_VALIDATE(params->level != api::power::LEVEL_NONE); | |
54 PowerAPI::Get(browser_context())->AddRequest(extension_id(), params->level); | 53 PowerAPI::Get(browser_context())->AddRequest(extension_id(), params->level); |
55 return true; | 54 return RespondNow(NoArguments()); |
56 } | 55 } |
57 | 56 |
58 bool PowerReleaseKeepAwakeFunction::RunSync() { | 57 ExtensionFunction::ResponseAction PowerReleaseKeepAwakeFunction::Run() { |
59 PowerAPI::Get(browser_context())->RemoveRequest(extension_id()); | 58 PowerAPI::Get(browser_context())->RemoveRequest(extension_id()); |
60 return true; | 59 return RespondNow(NoArguments()); |
61 } | 60 } |
62 | 61 |
63 // static | 62 // static |
64 PowerAPI* PowerAPI::Get(content::BrowserContext* context) { | 63 PowerAPI* PowerAPI::Get(content::BrowserContext* context) { |
65 return BrowserContextKeyedAPIFactory<PowerAPI>::Get(context); | 64 return BrowserContextKeyedAPIFactory<PowerAPI>::Get(context); |
66 } | 65 } |
67 | 66 |
68 // static | 67 // static |
69 BrowserContextKeyedAPIFactory<PowerAPI>* PowerAPI::GetFactoryInstance() { | 68 BrowserContextKeyedAPIFactory<PowerAPI>* PowerAPI::GetFactoryInstance() { |
70 return g_factory.Pointer(); | 69 return g_factory.Pointer(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 136 } |
138 | 137 |
139 void PowerAPI::Shutdown() { | 138 void PowerAPI::Shutdown() { |
140 // Unregister here rather than in the d'tor; otherwise this call will recreate | 139 // Unregister here rather than in the d'tor; otherwise this call will recreate |
141 // the already-deleted ExtensionRegistry. | 140 // the already-deleted ExtensionRegistry. |
142 ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); | 141 ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); |
143 power_save_blocker_.reset(); | 142 power_save_blocker_.reset(); |
144 } | 143 } |
145 | 144 |
146 } // namespace extensions | 145 } // namespace extensions |
OLD | NEW |