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 "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "content/browser/power_save_blocker_impl.h" | 10 #include "device/power_save_blocker/power_save_blocker_impl.h" |
11 #include "jni/PowerSaveBlocker_jni.h" | 11 #include "jni/PowerSaveBlocker_jni.h" |
12 #include "ui/android/view_android.h" | 12 #include "ui/android/view_android.h" |
13 | 13 |
14 namespace content { | 14 namespace device { |
15 | 15 |
16 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
17 | 17 |
18 class PowerSaveBlockerImpl::Delegate | 18 class PowerSaveBlockerImpl::Delegate |
19 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { | 19 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { |
20 public: | 20 public: |
21 Delegate(base::WeakPtr<ui::ViewAndroid> view_android, | 21 Delegate(base::WeakPtr<ui::ViewAndroid> view_android, |
22 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 22 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
23 | 23 |
24 // Does the actual work to apply or remove the desired power save block. | 24 // Does the actual work to apply or remove the desired power save block. |
(...skipping 14 matching lines...) Expand all Loading... |
39 }; | 39 }; |
40 | 40 |
41 PowerSaveBlockerImpl::Delegate::Delegate( | 41 PowerSaveBlockerImpl::Delegate::Delegate( |
42 base::WeakPtr<ui::ViewAndroid> view_android, | 42 base::WeakPtr<ui::ViewAndroid> view_android, |
43 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) | 43 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) |
44 : view_android_(view_android), ui_task_runner_(ui_task_runner) { | 44 : view_android_(view_android), ui_task_runner_(ui_task_runner) { |
45 JNIEnv* env = AttachCurrentThread(); | 45 JNIEnv* env = AttachCurrentThread(); |
46 java_power_save_blocker_.Reset(Java_PowerSaveBlocker_create(env)); | 46 java_power_save_blocker_.Reset(Java_PowerSaveBlocker_create(env)); |
47 } | 47 } |
48 | 48 |
49 PowerSaveBlockerImpl::Delegate::~Delegate() { | 49 PowerSaveBlockerImpl::Delegate::~Delegate() {} |
50 } | |
51 | 50 |
52 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { | 51 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { |
53 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 52 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
54 | 53 |
55 ScopedJavaLocalRef<jobject> obj(java_power_save_blocker_); | 54 ScopedJavaLocalRef<jobject> obj(java_power_save_blocker_); |
56 JNIEnv* env = AttachCurrentThread(); | 55 JNIEnv* env = AttachCurrentThread(); |
57 if (view_android_) { | 56 if (view_android_) { |
58 Java_PowerSaveBlocker_applyBlock( | 57 Java_PowerSaveBlocker_applyBlock( |
59 env, obj.obj(), view_android_->GetViewAndroidDelegate().obj()); | 58 env, obj.obj(), view_android_->GetViewAndroidDelegate().obj()); |
60 } | 59 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return; | 94 return; |
96 | 95 |
97 delegate_ = new Delegate(view_android, ui_task_runner_); | 96 delegate_ = new Delegate(view_android, ui_task_runner_); |
98 delegate_->ApplyBlock(); | 97 delegate_->ApplyBlock(); |
99 } | 98 } |
100 | 99 |
101 bool RegisterPowerSaveBlocker(JNIEnv* env) { | 100 bool RegisterPowerSaveBlocker(JNIEnv* env) { |
102 return RegisterNativesImpl(env); | 101 return RegisterNativesImpl(env); |
103 } | 102 } |
104 | 103 |
105 } // namespace content | 104 } // namespace device |
OLD | NEW |