| 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 "extensions/browser/api/idle/idle_manager.h" | 5 #include "extensions/browser/api/idle/idle_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 11 #include "extensions/browser/api/idle/idle_api_constants.h" | 12 #include "extensions/browser/api/idle/idle_api_constants.h" |
| 12 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
| 13 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/common/api/idle.h" | 15 #include "extensions/common/api/idle.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 | 17 |
| 17 namespace keys = extensions::idle_api_constants; | 18 namespace keys = extensions::idle_api_constants; |
| 18 namespace idle = extensions::api::idle; | 19 namespace idle = extensions::api::idle; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 DCHECK(thread_checker_.CalledOnValidThread()); | 174 DCHECK(thread_checker_.CalledOnValidThread()); |
| 174 idle_time_provider_->CalculateIdleState(threshold, notify); | 175 idle_time_provider_->CalculateIdleState(threshold, notify); |
| 175 } | 176 } |
| 176 | 177 |
| 177 void IdleManager::SetThreshold(const std::string& extension_id, int threshold) { | 178 void IdleManager::SetThreshold(const std::string& extension_id, int threshold) { |
| 178 DCHECK(thread_checker_.CalledOnValidThread()); | 179 DCHECK(thread_checker_.CalledOnValidThread()); |
| 179 GetMonitor(extension_id)->threshold = threshold; | 180 GetMonitor(extension_id)->threshold = threshold; |
| 180 } | 181 } |
| 181 | 182 |
| 182 // static | 183 // static |
| 183 base::StringValue* IdleManager::CreateIdleValue(ui::IdleState idle_state) { | 184 std::unique_ptr<base::StringValue> IdleManager::CreateIdleValue( |
| 185 ui::IdleState idle_state) { |
| 184 const char* description; | 186 const char* description; |
| 185 | 187 |
| 186 if (idle_state == ui::IDLE_STATE_ACTIVE) { | 188 if (idle_state == ui::IDLE_STATE_ACTIVE) { |
| 187 description = keys::kStateActive; | 189 description = keys::kStateActive; |
| 188 } else if (idle_state == ui::IDLE_STATE_IDLE) { | 190 } else if (idle_state == ui::IDLE_STATE_IDLE) { |
| 189 description = keys::kStateIdle; | 191 description = keys::kStateIdle; |
| 190 } else { | 192 } else { |
| 191 description = keys::kStateLocked; | 193 description = keys::kStateLocked; |
| 192 } | 194 } |
| 193 | 195 |
| 194 return new base::StringValue(description); | 196 return base::MakeUnique<base::StringValue>(description); |
| 195 } | 197 } |
| 196 | 198 |
| 197 void IdleManager::SetEventDelegateForTest( | 199 void IdleManager::SetEventDelegateForTest( |
| 198 std::unique_ptr<EventDelegate> event_delegate) { | 200 std::unique_ptr<EventDelegate> event_delegate) { |
| 199 DCHECK(thread_checker_.CalledOnValidThread()); | 201 DCHECK(thread_checker_.CalledOnValidThread()); |
| 200 event_delegate_ = std::move(event_delegate); | 202 event_delegate_ = std::move(event_delegate); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void IdleManager::SetIdleTimeProviderForTest( | 205 void IdleManager::SetIdleTimeProviderForTest( |
| 204 std::unique_ptr<IdleTimeProvider> idle_time_provider) { | 206 std::unique_ptr<IdleTimeProvider> idle_time_provider) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 event_delegate_->OnStateChanged(it->first, new_state); | 256 event_delegate_->OnStateChanged(it->first, new_state); |
| 255 monitor.last_state = new_state; | 257 monitor.last_state = new_state; |
| 256 listener_count += monitor.listeners; | 258 listener_count += monitor.listeners; |
| 257 } | 259 } |
| 258 | 260 |
| 259 if (listener_count == 0) | 261 if (listener_count == 0) |
| 260 StopPolling(); | 262 StopPolling(); |
| 261 } | 263 } |
| 262 | 264 |
| 263 } // namespace extensions | 265 } // namespace extensions |
| OLD | NEW |