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()->cookie_store()->GetCookieMonster() |
| 29 ->FlushStore(base::Closure()); |
| 30 } |
| 31 |
| 32 void CommitPendingWritesForProfile(Profile* profile) { |
| 33 // Both of these calls are asynchronous. They may not finish (and may not |
| 34 // even start!) before the Android OS kills our process. But we can't wait |
| 35 // for them to finish because blocking the UI thread is illegal. |
| 36 profile->GetPrefs()->CommitPendingWrite(); |
| 37 content::BrowserThread::PostTask( |
| 38 content::BrowserThread::IO, FROM_HERE, base::Bind( |
| 39 &FlushCookiesOnIOThread, |
| 40 make_scoped_refptr(profile->GetRequestContext()))); |
| 41 } |
| 42 } |
| 43 |
16 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { | 44 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { |
17 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); | 45 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); |
18 } | 46 } |
19 | 47 |
| 48 static void FlushPersistentData(JNIEnv* env, jclass obj) { |
| 49 // Commit the prending writes for all the loaded profiles. |
| 50 std::vector<Profile*> loaded_profiles = |
| 51 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 52 std::for_each(loaded_profiles.begin(), loaded_profiles.end(), |
| 53 CommitPendingWritesForProfile); |
| 54 |
| 55 if (g_browser_process->local_state()) |
| 56 g_browser_process->local_state()->CommitPendingWrite(); |
| 57 } |
| 58 |
20 namespace chrome { | 59 namespace chrome { |
21 namespace android { | 60 namespace android { |
22 | 61 |
23 // static | 62 // static |
24 bool ChromiumApplication::RegisterBindings(JNIEnv* env) { | 63 bool ChromiumApplication::RegisterBindings(JNIEnv* env) { |
25 return RegisterNativesImpl(env); | 64 return RegisterNativesImpl(env); |
26 } | 65 } |
27 | 66 |
28 void ChromiumApplication::OpenProtectedContentSettings() { | 67 void ChromiumApplication::OpenProtectedContentSettings() { |
29 Java_ChromiumApplication_openProtectedContentSettings( | 68 Java_ChromiumApplication_openProtectedContentSettings( |
(...skipping 24 matching lines...) Expand all Loading... |
54 } | 93 } |
55 | 94 |
56 bool ChromiumApplication::AreParentalControlsEnabled() { | 95 bool ChromiumApplication::AreParentalControlsEnabled() { |
57 return Java_ChromiumApplication_areParentalControlsEnabled( | 96 return Java_ChromiumApplication_areParentalControlsEnabled( |
58 base::android::AttachCurrentThread(), | 97 base::android::AttachCurrentThread(), |
59 base::android::GetApplicationContext()); | 98 base::android::GetApplicationContext()); |
60 } | 99 } |
61 | 100 |
62 } // namespace android | 101 } // namespace android |
63 } // namespace chrome | 102 } // namespace chrome |
OLD | NEW |