| 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 "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/android/tab_android.h" | 10 #include "chrome/browser/android/tab_android.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/net/predictor.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/common/chrome_content_client.h" | 15 #include "chrome/common/chrome_content_client.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "jni/ChromiumApplication_jni.h" | 18 #include "jni/ChromiumApplication_jni.h" |
| 18 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
| 19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 21 | 22 |
| 22 using base::android::ConvertUTF8ToJavaString; | 23 using base::android::ConvertUTF8ToJavaString; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 void FlushCookiesOnIOThread( | 26 void FlushCookiesOnIOThread( |
| 26 scoped_refptr<net::URLRequestContextGetter> getter) { | 27 scoped_refptr<net::URLRequestContextGetter> getter) { |
| 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 28 getter->GetURLRequestContext() | 29 getter->GetURLRequestContext() |
| 29 ->cookie_store() | 30 ->cookie_store() |
| 30 ->GetCookieMonster() | 31 ->GetCookieMonster() |
| 31 ->FlushStore(base::Closure()); | 32 ->FlushStore(base::Closure()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void CommitPendingWritesForProfile(Profile* profile) { | 35 void CommitPendingWritesForProfile(Profile* profile) { |
| 35 // Both of these calls are asynchronous. They may not finish (and may not | 36 // These calls are asynchronous. They may not finish (and may not even |
| 36 // even start!) before the Android OS kills our process. But we can't wait | 37 // start!) before the Android OS kills our process. But we can't wait for them |
| 37 // for them to finish because blocking the UI thread is illegal. | 38 // to finish because blocking the UI thread is illegal. |
| 38 profile->GetPrefs()->CommitPendingWrite(); | 39 profile->GetPrefs()->CommitPendingWrite(); |
| 39 content::BrowserThread::PostTask( | 40 content::BrowserThread::PostTask( |
| 40 content::BrowserThread::IO, FROM_HERE, | 41 content::BrowserThread::IO, FROM_HERE, |
| 41 base::Bind(&FlushCookiesOnIOThread, | 42 base::Bind(&FlushCookiesOnIOThread, |
| 42 make_scoped_refptr(profile->GetRequestContext()))); | 43 make_scoped_refptr(profile->GetRequestContext()))); |
| 44 profile->GetNetworkPredictor()->SaveStateForNextStartupAndTrim(); |
| 43 } | 45 } |
| 44 } // namespace | 46 } // namespace |
| 45 | 47 |
| 46 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { | 48 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { |
| 47 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); | 49 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); |
| 48 } | 50 } |
| 49 | 51 |
| 50 static void FlushPersistentData(JNIEnv* env, jclass obj) { | 52 static void FlushPersistentData(JNIEnv* env, jclass obj) { |
| 51 // Commit the prending writes for all the loaded profiles. | 53 // Commit the prending writes for all the loaded profiles. |
| 52 std::vector<Profile*> loaded_profiles = | 54 std::vector<Profile*> loaded_profiles = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 97 } |
| 96 | 98 |
| 97 bool ChromiumApplication::AreParentalControlsEnabled() { | 99 bool ChromiumApplication::AreParentalControlsEnabled() { |
| 98 return Java_ChromiumApplication_areParentalControlsEnabled( | 100 return Java_ChromiumApplication_areParentalControlsEnabled( |
| 99 base::android::AttachCurrentThread(), | 101 base::android::AttachCurrentThread(), |
| 100 base::android::GetApplicationContext()); | 102 base::android::GetApplicationContext()); |
| 101 } | 103 } |
| 102 | 104 |
| 103 } // namespace android | 105 } // namespace android |
| 104 } // namespace chrome | 106 } // namespace chrome |
| OLD | NEW |