OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/android/chromium_application.h" | 5 #include "chrome/browser/android/chromium_application.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/android/tab_android.h" | 10 #include "chrome/browser/android/tab_android.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/common/chrome_content_client.h" | 14 #include "chrome/common/chrome_content_client.h" |
| 15 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
12 #include "jni/ChromiumApplication_jni.h" | 17 #include "jni/ChromiumApplication_jni.h" |
| 18 #include "net/cookies/cookie_monster.h" |
| 19 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_context_getter.h" |
13 | 21 |
14 using base::android::ConvertUTF8ToJavaString; | 22 using base::android::ConvertUTF8ToJavaString; |
15 | 23 |
| 24 namespace { |
| 25 void FlushCookiesOnIOThread( |
| 26 scoped_refptr<net::URLRequestContextGetter> getter) { |
| 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 28 getter->GetURLRequestContext() |
| 29 ->cookie_store() |
| 30 ->GetCookieMonster() |
| 31 ->FlushStore(base::Closure()); |
| 32 } |
| 33 |
| 34 void CommitPendingWritesForProfile(Profile* profile) { |
| 35 // Both of these calls are asynchronous. They may not finish (and may not |
| 36 // even start!) before the Android OS kills our process. But we can't wait |
| 37 // for them to finish because blocking the UI thread is illegal. |
| 38 profile->GetPrefs()->CommitPendingWrite(); |
| 39 content::BrowserThread::PostTask( |
| 40 content::BrowserThread::IO, FROM_HERE, |
| 41 base::Bind(&FlushCookiesOnIOThread, |
| 42 make_scoped_refptr(profile->GetRequestContext()))); |
| 43 } |
| 44 } // namespace |
| 45 |
16 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { | 46 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { |
17 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); | 47 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); |
18 } | 48 } |
19 | 49 |
| 50 static void FlushPersistentData(JNIEnv* env, jclass obj) { |
| 51 // Commit the prending writes for all the loaded profiles. |
| 52 std::vector<Profile*> loaded_profiles = |
| 53 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 54 std::for_each(loaded_profiles.begin(), loaded_profiles.end(), |
| 55 CommitPendingWritesForProfile); |
| 56 |
| 57 if (g_browser_process->local_state()) |
| 58 g_browser_process->local_state()->CommitPendingWrite(); |
| 59 } |
| 60 |
20 namespace chrome { | 61 namespace chrome { |
21 namespace android { | 62 namespace android { |
22 | 63 |
23 // static | 64 // static |
24 bool ChromiumApplication::RegisterBindings(JNIEnv* env) { | 65 bool ChromiumApplication::RegisterBindings(JNIEnv* env) { |
25 return RegisterNativesImpl(env); | 66 return RegisterNativesImpl(env); |
26 } | 67 } |
27 | 68 |
28 void ChromiumApplication::OpenProtectedContentSettings() { | 69 void ChromiumApplication::OpenProtectedContentSettings() { |
29 Java_ChromiumApplication_openProtectedContentSettings( | 70 Java_ChromiumApplication_openProtectedContentSettings( |
(...skipping 24 matching lines...) Expand all Loading... |
54 } | 95 } |
55 | 96 |
56 bool ChromiumApplication::AreParentalControlsEnabled() { | 97 bool ChromiumApplication::AreParentalControlsEnabled() { |
57 return Java_ChromiumApplication_areParentalControlsEnabled( | 98 return Java_ChromiumApplication_areParentalControlsEnabled( |
58 base::android::AttachCurrentThread(), | 99 base::android::AttachCurrentThread(), |
59 base::android::GetApplicationContext()); | 100 base::android::GetApplicationContext()); |
60 } | 101 } |
61 | 102 |
62 } // namespace android | 103 } // namespace android |
63 } // namespace chrome | 104 } // namespace chrome |
OLD | NEW |