Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/android/chromium_application.cc

Issue 1059863002: Upstream the last native calls in the Application. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/net/predictor.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/safe_browsing/protocol_manager.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/common/chrome_content_client.h" 17 #include "chrome/common/chrome_content_client.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "jni/ChromiumApplication_jni.h" 20 #include "jni/ChromiumApplication_jni.h"
19 #include "net/cookies/cookie_monster.h" 21 #include "net/cookies/cookie_monster.h"
22 #include "net/cookies/cookie_store.h"
20 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
22 25
23 using base::android::ConvertUTF8ToJavaString; 26 using base::android::ConvertUTF8ToJavaString;
24 27
25 namespace { 28 namespace {
29
26 void FlushCookiesOnIOThread( 30 void FlushCookiesOnIOThread(
27 scoped_refptr<net::URLRequestContextGetter> getter) { 31 scoped_refptr<net::URLRequestContextGetter> getter) {
28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
29 getter->GetURLRequestContext() 33 getter->GetURLRequestContext()
30 ->cookie_store() 34 ->cookie_store()
31 ->GetCookieMonster() 35 ->GetCookieMonster()
32 ->FlushStore(base::Closure()); 36 ->FlushStore(base::Closure());
33 } 37 }
34 38
35 void CommitPendingWritesForProfile(Profile* profile) { 39 void CommitPendingWritesForProfile(Profile* profile) {
36 // These calls are asynchronous. They may not finish (and may not even 40 // These calls are asynchronous. They may not finish (and may not even
37 // start!) before the Android OS kills our process. But we can't wait for them 41 // start!) before the Android OS kills our process. But we can't wait for them
38 // to finish because blocking the UI thread is illegal. 42 // to finish because blocking the UI thread is illegal.
39 profile->GetPrefs()->CommitPendingWrite(); 43 profile->GetPrefs()->CommitPendingWrite();
40 content::BrowserThread::PostTask( 44 content::BrowserThread::PostTask(
41 content::BrowserThread::IO, FROM_HERE, 45 content::BrowserThread::IO, FROM_HERE,
42 base::Bind(&FlushCookiesOnIOThread, 46 base::Bind(&FlushCookiesOnIOThread,
43 make_scoped_refptr(profile->GetRequestContext()))); 47 make_scoped_refptr(profile->GetRequestContext())));
44 profile->GetNetworkPredictor()->SaveStateForNextStartupAndTrim(); 48 profile->GetNetworkPredictor()->SaveStateForNextStartupAndTrim();
45 } 49 }
50
51 void RemoveSessionCookiesOnIOThread(
52 scoped_refptr<net::URLRequestContextGetter> getter) {
53 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
54 getter->GetURLRequestContext()->cookie_store()->DeleteSessionCookiesAsync(
55 net::CookieStore::DeleteCallback());
56 }
57
58 void RemoveSessionCookiesForProfile(Profile* profile) {
59 content::BrowserThread::PostTask(
60 content::BrowserThread::IO, FROM_HERE,
61 base::Bind(&RemoveSessionCookiesOnIOThread,
62 make_scoped_refptr(profile->GetRequestContext())));
63 }
64
65 void ChangeAppStatusOnIOThread(SafeBrowsingService* sb_service,
66 jboolean foreground) {
67 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
68 SafeBrowsingProtocolManager* proto_manager = sb_service->protocol_manager();
69 if (proto_manager)
70 proto_manager->SetAppInForeground(foreground);
71 }
72
46 } // namespace 73 } // namespace
47 74
48 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) { 75 static jstring GetBrowserUserAgent(JNIEnv* env, jclass clazz) {
49 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); 76 return ConvertUTF8ToJavaString(env, GetUserAgent()).Release();
50 } 77 }
51 78
52 static void FlushPersistentData(JNIEnv* env, jclass obj) { 79 static void FlushPersistentData(JNIEnv* env, jclass obj) {
53 // Commit the prending writes for all the loaded profiles. 80 // Commit the prending writes for all the loaded profiles.
54 std::vector<Profile*> loaded_profiles = 81 std::vector<Profile*> loaded_profiles =
55 g_browser_process->profile_manager()->GetLoadedProfiles(); 82 g_browser_process->profile_manager()->GetLoadedProfiles();
56 std::for_each(loaded_profiles.begin(), loaded_profiles.end(), 83 std::for_each(loaded_profiles.begin(), loaded_profiles.end(),
57 CommitPendingWritesForProfile); 84 CommitPendingWritesForProfile);
58 85
59 if (g_browser_process->local_state()) 86 if (g_browser_process->local_state())
60 g_browser_process->local_state()->CommitPendingWrite(); 87 g_browser_process->local_state()->CommitPendingWrite();
61 } 88 }
62 89
90 static void RemoveSessionCookies(JNIEnv* env, jclass obj) {
91 std::vector<Profile*> loaded_profiles =
92 g_browser_process->profile_manager()->GetLoadedProfiles();
93 std::for_each(loaded_profiles.begin(), loaded_profiles.end(),
94 RemoveSessionCookiesForProfile);
95 }
96
97 static void ChangeAppStatus(JNIEnv* env, jclass obj, jboolean foreground) {
98 content::BrowserThread::PostTask(
99 content::BrowserThread::IO, FROM_HERE,
100 base::Bind(&ChangeAppStatusOnIOThread,
101 base::Unretained(g_browser_process->safe_browsing_service()),
102 foreground));
103 }
104
63 namespace chrome { 105 namespace chrome {
64 namespace android { 106 namespace android {
65 107
66 // static 108 // static
67 bool ChromiumApplication::RegisterBindings(JNIEnv* env) { 109 bool ChromiumApplication::RegisterBindings(JNIEnv* env) {
68 return RegisterNativesImpl(env); 110 return RegisterNativesImpl(env);
69 } 111 }
70 112
71 void ChromiumApplication::OpenProtectedContentSettings() { 113 void ChromiumApplication::OpenProtectedContentSettings() {
72 Java_ChromiumApplication_openProtectedContentSettings( 114 Java_ChromiumApplication_openProtectedContentSettings(
(...skipping 24 matching lines...) Expand all
97 } 139 }
98 140
99 bool ChromiumApplication::AreParentalControlsEnabled() { 141 bool ChromiumApplication::AreParentalControlsEnabled() {
100 return Java_ChromiumApplication_areParentalControlsEnabled( 142 return Java_ChromiumApplication_areParentalControlsEnabled(
101 base::android::AttachCurrentThread(), 143 base::android::AttachCurrentThread(),
102 base::android::GetApplicationContext()); 144 base::android::GetApplicationContext());
103 } 145 }
104 146
105 } // namespace android 147 } // namespace android
106 } // namespace chrome 148 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698