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

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

Issue 10816038: Upstreaming RegisterProcessUtils() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/android/chrome_jni_registrar.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/process_utils.h" 5 #include "chrome/browser/android/process_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
13 #include "jni/ProcessUtils_jni.h" 17 #include "jni/ProcessUtils_jni.h"
18 #include "net/http/http_network_session.h"
19 #include "net/http/http_transaction_factory.h"
20 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_context_getter.h"
14 22
15 namespace { 23 namespace {
16 24
25 void CloseIdleConnectionsForProfile(
26 scoped_refptr<net::URLRequestContextGetter> context_getter) {
27 DCHECK(context_getter.get());
28 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
29 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
30 base::Bind(&CloseIdleConnectionsForProfile,
31 context_getter));
32 return;
33 }
34
35 net::URLRequestContext* context = context_getter->GetURLRequestContext();
36 DCHECK(context->http_transaction_factory());
37 net::HttpNetworkSession* session =
38 context->http_transaction_factory()->GetSession();
39 DCHECK(session);
Philippe 2012/12/03 13:17:46 Are we missing 'session->CloseIdleConnections()' h
digit1 2012/12/03 13:42:02 Yes, this looks suspicious. What happens if you ad
Philippe 2012/12/03 13:48:37 Yes, I'm building/testing this right now. FYI, we
40 }
41
17 // Only accessed from the JNI thread by ToggleWebKitSharedTimers() which is 42 // Only accessed from the JNI thread by ToggleWebKitSharedTimers() which is
18 // implemented below. 43 // implemented below.
19 base::LazyInstance<std::vector<int /* process id */> > g_suspended_processes = 44 base::LazyInstance<std::vector<int /* process id */> > g_suspended_processes =
20 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
21 46
22 // Suspends timers in all current render processes. 47 // Suspends timers in all current render processes.
23 void SuspendWebKitSharedTimers(std::vector<int>* suspended_processes) { 48 void SuspendWebKitSharedTimers(std::vector<int>* suspended_processes) {
24 for (content::RenderProcessHost::iterator i( 49 for (content::RenderProcessHost::iterator i(
25 content::RenderProcessHost::AllHostsIterator()); 50 content::RenderProcessHost::AllHostsIterator());
26 !i.IsAtEnd(); i.Advance()) { 51 !i.IsAtEnd(); i.Advance()) {
(...skipping 20 matching lines...) Expand all
47 std::vector<int>* suspended_processes = &g_suspended_processes.Get(); 72 std::vector<int>* suspended_processes = &g_suspended_processes.Get();
48 if (suspend) { 73 if (suspend) {
49 DCHECK(suspended_processes->empty()); 74 DCHECK(suspended_processes->empty());
50 SuspendWebKitSharedTimers(suspended_processes); 75 SuspendWebKitSharedTimers(suspended_processes);
51 } else { 76 } else {
52 ResumeWebkitSharedTimers(*suspended_processes); 77 ResumeWebkitSharedTimers(*suspended_processes);
53 suspended_processes->clear(); 78 suspended_processes->clear();
54 } 79 }
55 } 80 }
56 81
57 // TODO(pliard): http://crbug.com/137674 82 static void CloseIdleConnections(JNIEnv* env, jclass obj) {
83 // Iterate through all loaded profiles (and their associated incognito
84 // profiles if created), and close the idle connections associated with each
85 // one.
86 std::vector<Profile*> profiles(
87 g_browser_process->profile_manager()->GetLoadedProfiles());
88 for (std::vector<Profile*>::iterator i = profiles.begin();
89 i != profiles.end(); i++) {
90 Profile* profile = *i;
91 CloseIdleConnectionsForProfile(profile->GetRequestContext());
92 if (profile->HasOffTheRecordProfile()) {
93 CloseIdleConnectionsForProfile(
94 profile->GetOffTheRecordProfile()->GetRequestContext());
95 }
96 }
97 }
98
58 bool RegisterProcessUtils(JNIEnv* env) { 99 bool RegisterProcessUtils(JNIEnv* env) {
59 return RegisterNativesImpl(env); 100 return RegisterNativesImpl(env);
60 } 101 }
OLDNEW
« no previous file with comments | « chrome/browser/android/chrome_jni_registrar.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698