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

Side by Side Diff: chrome/browser/instant/instant_service.cc

Issue 11896113: Add chrome-search: access from Instant overlay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yet another rebase Created 7 years, 9 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
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/instant/instant_service.h" 5 #include "chrome/browser/instant/instant_service.h"
6 6
7 #include "chrome/browser/instant/instant_io_context.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
10 #include "chrome/common/chrome_notification_types.h"
11 #include "content/public/browser/browser_thread.h"
7 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
8 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
9 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/url_data_source.h"
10 16
11 InstantService::InstantService() { 17 using content::BrowserThread;
18
19 InstantService::InstantService(Profile* profile)
20 : profile_(profile) {
21 // Stub for unit tests.
22 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
23 return;
24
12 registrar_.Add(this, 25 registrar_.Add(this,
13 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 26 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
14 content::NotificationService::AllSources()); 27 content::NotificationService::AllSources());
28
29 instant_io_context_ = new InstantIOContext();
30
31 if (profile_ && profile_->GetResourceContext()) {
32 BrowserThread::PostTask(
33 BrowserThread::IO, FROM_HERE,
34 base::Bind(&InstantIOContext::SetUserDataOnIO,
35 profile->GetResourceContext(), instant_io_context_));
36 }
37
38 content::URLDataSource::Add(profile, new ThumbnailSource(profile));
15 } 39 }
16 40
17 InstantService::~InstantService() { 41 InstantService::~InstantService() {
18 } 42 }
19 43
20 void InstantService::AddInstantProcess(int process_id) { 44 void InstantService::AddInstantProcess(int process_id) {
21 process_ids_.insert(process_id); 45 process_ids_.insert(process_id);
46
47 if (instant_io_context_) {
48 BrowserThread::PostTask(
49 BrowserThread::IO, FROM_HERE,
50 base::Bind(&InstantIOContext::AddInstantProcessOnIO,
51 instant_io_context_, process_id));
52 }
22 } 53 }
23 54
24 bool InstantService::IsInstantProcess(int process_id) const { 55 bool InstantService::IsInstantProcess(int process_id) const {
25 return process_ids_.find(process_id) != process_ids_.end(); 56 return process_ids_.find(process_id) != process_ids_.end();
26 } 57 }
27 58
28 void InstantService::Shutdown() { 59 void InstantService::Shutdown() {
29 process_ids_.clear(); 60 process_ids_.clear();
61
62 if (instant_io_context_) {
63 BrowserThread::PostTask(
64 BrowserThread::IO, FROM_HERE,
65 base::Bind(&InstantIOContext::ClearInstantProcessesOnIO,
66 instant_io_context_));
67 }
68 instant_io_context_ = NULL;
30 } 69 }
31 70
32 void InstantService::Observe(int type, 71 void InstantService::Observe(int type,
33 const content::NotificationSource& source, 72 const content::NotificationSource& source,
34 const content::NotificationDetails& details) { 73 const content::NotificationDetails& details) {
74 DCHECK_EQ(type, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
35 int process_id = content::Source<content::RenderProcessHost>(source)->GetID(); 75 int process_id = content::Source<content::RenderProcessHost>(source)->GetID();
36 process_ids_.erase(process_id); 76 process_ids_.erase(process_id);
77
78 if (instant_io_context_) {
79 BrowserThread::PostTask(
80 BrowserThread::IO, FROM_HERE,
81 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
82 instant_io_context_, process_id));
83 }
37 } 84 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_service.h ('k') | chrome/browser/instant/instant_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698