OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "chrome/browser/android/preferences/clipboard_android.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/time/time.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/prefs/pref_registry_simple.h" |
| 12 #include "components/prefs/pref_service.h" |
| 13 #include "ui/base/clipboard/clipboard.h" |
| 14 #include "ui/base/clipboard/clipboard_android.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 void HandleClipboardModified(PrefService* local_state, base::Time time) { |
| 19 local_state->SetInt64(prefs::kClipboardLastModifiedTime, |
| 20 time.ToInternalValue()); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 namespace android { |
| 26 |
| 27 void RegisterClipboardAndroidPrefs(PrefRegistrySimple* registry) { |
| 28 registry->RegisterInt64Pref(prefs::kClipboardLastModifiedTime, 0u); |
| 29 } |
| 30 |
| 31 void InitClipboardAndroidFromLocalState(PrefService* local_state) { |
| 32 DCHECK(local_state); |
| 33 // Given the context, the cast is guaranteed to succeed. |
| 34 ui::ClipboardAndroid* clipboard = |
| 35 static_cast<ui::ClipboardAndroid*>(ui::Clipboard::GetForCurrentThread()); |
| 36 clipboard->SetLastModifiedTimeWithoutRunningCallback( |
| 37 base::Time::FromInternalValue( |
| 38 local_state->GetInt64(prefs::kClipboardLastModifiedTime))); |
| 39 clipboard->SetModifiedCallback( |
| 40 base::Bind(&HandleClipboardModified, local_state)); |
| 41 } |
| 42 |
| 43 } // namespace android |
OLD | NEW |