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

Side by Side Diff: chrome/profile_import/profile_import_thread.cc

Issue 3581008: Fix instances of passing raw pointers to RefCounted objects in tasks. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Merge Created 10 years, 2 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/profile_import/profile_import_thread.h ('k') | chrome/service/service_process.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/profile_import/profile_import_thread.h" 5 #include "chrome/profile_import/profile_import_thread.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/importer/importer.h" 10 #include "chrome/browser/importer/importer.h"
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 ProfileImportThread::ProfileImportThread() 27 ProfileImportThread::ProfileImportThread()
28 : bridge_(NULL), 28 : bridge_(NULL),
29 browser_type_(0), 29 browser_type_(0),
30 items_to_import_(0), 30 items_to_import_(0),
31 importer_(NULL) { 31 importer_(NULL) {
32 ChildProcess::current()->AddRefProcess(); // Balanced in Cleanup(). 32 ChildProcess::current()->AddRefProcess(); // Balanced in Cleanup().
33 } 33 }
34 34
35 ProfileImportThread::~ProfileImportThread() {}
36
35 void ProfileImportThread::OnControlMessageReceived(const IPC::Message& msg) { 37 void ProfileImportThread::OnControlMessageReceived(const IPC::Message& msg) {
36 IPC_BEGIN_MESSAGE_MAP(ProfileImportThread, msg) 38 IPC_BEGIN_MESSAGE_MAP(ProfileImportThread, msg)
37 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_StartImport, 39 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_StartImport,
38 OnImportStart) 40 OnImportStart)
39 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, 41 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport,
40 OnImportCancel) 42 OnImportCancel)
41 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished, 43 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished,
42 OnImportItemFinished) 44 OnImportItemFinished)
43 IPC_END_MESSAGE_MAP() 45 IPC_END_MESSAGE_MAP()
44 } 46 }
45 47
46 void ProfileImportThread::OnImportStart( 48 void ProfileImportThread::OnImportStart(
47 const ProfileInfo& profile_info, 49 const ProfileInfo& profile_info,
48 int items, 50 int items,
49 const DictionaryValue& localized_strings, 51 const DictionaryValue& localized_strings,
50 bool import_to_bookmark_bar) { 52 bool import_to_bookmark_bar) {
51 bridge_ = new ExternalProcessImporterBridge(this, localized_strings); 53 bridge_ = new ExternalProcessImporterBridge(this, localized_strings);
52 bridge_->AddRef(); // Balanced in Cleanup().
53 54
54 ImporterList importer_list; 55 ImporterList importer_list;
55 importer_ = importer_list.CreateImporterByType(profile_info.browser_type); 56 importer_ = importer_list.CreateImporterByType(profile_info.browser_type);
56 if (!importer_) { 57 if (!importer_) {
57 Send(new ProfileImportProcessHostMsg_Import_Finished(false, 58 Send(new ProfileImportProcessHostMsg_Import_Finished(false,
58 "Importer could not be created.")); 59 "Importer could not be created."));
59 return; 60 return;
60 } 61 }
61 62
62 importer_->AddRef(); // Balanced in Cleanup().
63 importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); 63 importer_->set_import_to_bookmark_bar(import_to_bookmark_bar);
64 items_to_import_ = items; 64 items_to_import_ = items;
65 65
66 // Create worker thread in which importer runs. 66 // Create worker thread in which importer runs.
67 import_thread_.reset(new base::Thread("import_thread")); 67 import_thread_.reset(new base::Thread("import_thread"));
68 base::Thread::Options options; 68 base::Thread::Options options;
69 options.message_loop_type = MessageLoop::TYPE_IO; 69 options.message_loop_type = MessageLoop::TYPE_IO;
70 if (!import_thread_->StartWithOptions(options)) { 70 if (!import_thread_->StartWithOptions(options)) {
71 NOTREACHED(); 71 NOTREACHED();
72 Cleanup(); 72 Cleanup();
73 } 73 }
74 import_thread_->message_loop()->PostTask(FROM_HERE, 74 import_thread_->message_loop()->PostTask(
75 NewRunnableMethod(importer_, &Importer::StartImport, 75 FROM_HERE,
76 profile_info, items, bridge_)); 76 NewRunnableMethod(
77 importer_.get(),
78 &Importer::StartImport,
79 profile_info,
80 items,
81 bridge_));
77 } 82 }
78 83
79 void ProfileImportThread::OnImportCancel() { 84 void ProfileImportThread::OnImportCancel() {
80 Cleanup(); 85 Cleanup();
81 } 86 }
82 87
83 void ProfileImportThread::OnImportItemFinished(uint16 item) { 88 void ProfileImportThread::OnImportItemFinished(uint16 item) {
84 items_to_import_ ^= item; // Remove finished item from mask. 89 items_to_import_ ^= item; // Remove finished item from mask.
85 // If we've finished with all items, notify the browser process. 90 // If we've finished with all items, notify the browser process.
86 if (items_to_import_ == 0) 91 if (items_to_import_ == 0)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 std::vector<TemplateURL> urls; 182 std::vector<TemplateURL> urls;
178 for (size_t i = 0; i < template_urls.size(); ++i) { 183 for (size_t i = 0; i < template_urls.size(); ++i) {
179 urls.push_back(*template_urls[i]); 184 urls.push_back(*template_urls[i]);
180 } 185 }
181 Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(urls, 186 Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(urls,
182 default_keyword_index, unique_on_host_and_path)); 187 default_keyword_index, unique_on_host_and_path));
183 } 188 }
184 189
185 void ProfileImportThread::Cleanup() { 190 void ProfileImportThread::Cleanup() {
186 importer_->Cancel(); 191 importer_->Cancel();
187 importer_->Release(); 192 importer_ = NULL;
188 bridge_->Release(); 193 bridge_ = NULL;
189 ChildProcess::current()->ReleaseProcess(); 194 ChildProcess::current()->ReleaseProcess();
190 } 195 }
OLDNEW
« no previous file with comments | « chrome/profile_import/profile_import_thread.h ('k') | chrome/service/service_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698