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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.cc

Issue 2751573004: Image writer client: create mojo client with MakeUnique<> (Closed)
Patch Set: Created 3 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
« no previous file with comments | « chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/api/image_writer_private/image_writer_utilit y_client.h" 5 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utilit y_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const ErrorCallback& error_callback, 65 const ErrorCallback& error_callback,
66 const base::FilePath& source, 66 const base::FilePath& source,
67 const base::FilePath& target) { 67 const base::FilePath& target) {
68 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 68 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
69 DCHECK(!removable_storage_writer_client_); 69 DCHECK(!removable_storage_writer_client_);
70 70
71 progress_callback_ = progress_callback; 71 progress_callback_ = progress_callback;
72 success_callback_ = success_callback; 72 success_callback_ = success_callback;
73 error_callback_ = error_callback; 73 error_callback_ = error_callback;
74 74
75 StartUtilityProcess(); 75 StartUtilityProcessIfNeeded();
76 76
77 extensions::mojom::RemovableStorageWriterClientPtr client; 77 extensions::mojom::RemovableStorageWriterClientPtr client;
78 removable_storage_writer_client_ = 78 removable_storage_writer_client_ =
79 base::MakeUnique<RemovableStorageWriterClientImpl>(this, &client); 79 base::MakeUnique<RemovableStorageWriterClientImpl>(this, &client);
80 80
81 utility_process_mojo_client_->service()->Write(source, target, 81 utility_process_mojo_client_->service()->Write(source, target,
82 std::move(client)); 82 std::move(client));
83 } 83 }
84 84
85 void ImageWriterUtilityClient::Verify(const ProgressCallback& progress_callback, 85 void ImageWriterUtilityClient::Verify(const ProgressCallback& progress_callback,
86 const SuccessCallback& success_callback, 86 const SuccessCallback& success_callback,
87 const ErrorCallback& error_callback, 87 const ErrorCallback& error_callback,
88 const base::FilePath& source, 88 const base::FilePath& source,
89 const base::FilePath& target) { 89 const base::FilePath& target) {
90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
91 DCHECK(!removable_storage_writer_client_); 91 DCHECK(!removable_storage_writer_client_);
92 92
93 progress_callback_ = progress_callback; 93 progress_callback_ = progress_callback;
94 success_callback_ = success_callback; 94 success_callback_ = success_callback;
95 error_callback_ = error_callback; 95 error_callback_ = error_callback;
96 96
97 StartUtilityProcess(); 97 StartUtilityProcessIfNeeded();
98 98
99 extensions::mojom::RemovableStorageWriterClientPtr client; 99 extensions::mojom::RemovableStorageWriterClientPtr client;
100 removable_storage_writer_client_ = 100 removable_storage_writer_client_ =
101 base::MakeUnique<RemovableStorageWriterClientImpl>(this, &client); 101 base::MakeUnique<RemovableStorageWriterClientImpl>(this, &client);
102 102
103 utility_process_mojo_client_->service()->Verify(source, target, 103 utility_process_mojo_client_->service()->Verify(source, target,
104 std::move(client)); 104 std::move(client));
105 } 105 }
106 106
107 void ImageWriterUtilityClient::Cancel(const CancelCallback& cancel_callback) { 107 void ImageWriterUtilityClient::Cancel(const CancelCallback& cancel_callback) {
108 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
109 109
110 ResetRequest(); 110 ResetRequest();
111 task_runner_->PostTask(FROM_HERE, cancel_callback); 111 task_runner_->PostTask(FROM_HERE, cancel_callback);
112 } 112 }
113 113
114 void ImageWriterUtilityClient::Shutdown() { 114 void ImageWriterUtilityClient::Shutdown() {
115 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 115 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
116 116
117 ResetRequest(); 117 ResetRequest();
118 utility_process_mojo_client_.reset(); 118 utility_process_mojo_client_.reset();
119 } 119 }
120 120
121 void ImageWriterUtilityClient::StartUtilityProcess() { 121 void ImageWriterUtilityClient::StartUtilityProcessIfNeeded() {
122 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 122 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
123 123
124 if (utility_process_mojo_client_) 124 if (utility_process_mojo_client_)
125 return; 125 return;
126 126
127 const base::string16 utility_process_name = 127 utility_process_mojo_client_ =
128 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_IMAGE_WRITER_NAME); 128 base::MakeUnique<content::UtilityProcessMojoClient<
129 129 extensions::mojom::RemovableStorageWriter>>(
130 utility_process_mojo_client_.reset( 130 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_IMAGE_WRITER_NAME));
131 new content::UtilityProcessMojoClient<
132 extensions::mojom::RemovableStorageWriter>(utility_process_name));
133 utility_process_mojo_client_->set_error_callback( 131 utility_process_mojo_client_->set_error_callback(
134 base::Bind(&ImageWriterUtilityClient::UtilityProcessError, this)); 132 base::Bind(&ImageWriterUtilityClient::UtilityProcessError, this));
135 133
136 utility_process_mojo_client_->set_disable_sandbox(); 134 utility_process_mojo_client_->set_disable_sandbox();
137 #if defined(OS_WIN) 135 #if defined(OS_WIN)
138 utility_process_mojo_client_->set_run_elevated(); 136 utility_process_mojo_client_->set_run_elevated();
139 #endif 137 #endif
140 138
141 utility_process_mojo_client_->Start(); 139 utility_process_mojo_client_->Start();
142 } 140 }
(...skipping 25 matching lines...) Expand all
168 } 166 }
169 167
170 void ImageWriterUtilityClient::ResetRequest() { 168 void ImageWriterUtilityClient::ResetRequest() {
171 removable_storage_writer_client_.reset(); 169 removable_storage_writer_client_.reset();
172 170
173 // Clear handlers to not hold any reference to the caller. 171 // Clear handlers to not hold any reference to the caller.
174 progress_callback_.Reset(); 172 progress_callback_.Reset();
175 success_callback_.Reset(); 173 success_callback_.Reset();
176 error_callback_.Reset(); 174 error_callback_.Reset();
177 } 175 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/image_writer_private/image_writer_utility_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698