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

Side by Side Diff: chrome/common/service_process_util.cc

Issue 1880143002: Convert chrome/common to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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/common/service_process_util.h ('k') | chrome/common/service_process_util_linux.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) 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/common/service_process_util.h" 5 #include "chrome/common/service_process_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory>
10 11
11 #include "base/base_switches.h" 12 #include "base/base_switches.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/sha1.h" 18 #include "base/sha1.h"
18 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const std::string& append_str) { 113 const std::string& append_str) {
113 std::string versioned_str; 114 std::string versioned_str;
114 versioned_str.append(version_info::GetVersionNumber()); 115 versioned_str.append(version_info::GetVersionNumber());
115 versioned_str.append(append_str); 116 versioned_str.append(append_str);
116 return GetServiceProcessScopedName(versioned_str); 117 return GetServiceProcessScopedName(versioned_str);
117 } 118 }
118 119
119 // Reads the named shared memory to get the shared data. Returns false if no 120 // Reads the named shared memory to get the shared data. Returns false if no
120 // matching shared memory was found. 121 // matching shared memory was found.
121 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { 122 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) {
122 scoped_ptr<base::SharedMemory> shared_mem_service_data; 123 std::unique_ptr<base::SharedMemory> shared_mem_service_data;
123 shared_mem_service_data.reset(new base::SharedMemory()); 124 shared_mem_service_data.reset(new base::SharedMemory());
124 ServiceProcessSharedData* service_data = NULL; 125 ServiceProcessSharedData* service_data = NULL;
125 if (shared_mem_service_data.get() && 126 if (shared_mem_service_data.get() &&
126 shared_mem_service_data->Open(GetServiceProcessSharedMemName(), true) && 127 shared_mem_service_data->Open(GetServiceProcessSharedMemName(), true) &&
127 shared_mem_service_data->Map(sizeof(ServiceProcessSharedData))) { 128 shared_mem_service_data->Map(sizeof(ServiceProcessSharedData))) {
128 service_data = reinterpret_cast<ServiceProcessSharedData*>( 129 service_data = reinterpret_cast<ServiceProcessSharedData*>(
129 shared_mem_service_data->memory()); 130 shared_mem_service_data->memory());
130 // Make sure the version in shared memory is null-terminated. If it is not, 131 // Make sure the version in shared memory is null-terminated. If it is not,
131 // treat it as invalid. 132 // treat it as invalid.
132 if (version && memchr(service_data->service_process_version, '\0', 133 if (version && memchr(service_data->service_process_version, '\0',
(...skipping 17 matching lines...) Expand all
150 #if defined(OS_WIN) 151 #if defined(OS_WIN)
151 std::string user_data_dir_path = base::WideToUTF8(user_data_dir.value()); 152 std::string user_data_dir_path = base::WideToUTF8(user_data_dir.value());
152 #elif defined(OS_POSIX) 153 #elif defined(OS_POSIX)
153 std::string user_data_dir_path = user_data_dir.value(); 154 std::string user_data_dir_path = user_data_dir.value();
154 #endif // defined(OS_WIN) 155 #endif // defined(OS_WIN)
155 std::string hash = base::SHA1HashString(user_data_dir_path); 156 std::string hash = base::SHA1HashString(user_data_dir_path);
156 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length()); 157 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length());
157 return hex_hash + "." + append_str; 158 return hex_hash + "." + append_str;
158 } 159 }
159 160
160 scoped_ptr<base::CommandLine> CreateServiceProcessCommandLine() { 161 std::unique_ptr<base::CommandLine> CreateServiceProcessCommandLine() {
161 base::FilePath exe_path; 162 base::FilePath exe_path;
162 PathService::Get(content::CHILD_PROCESS_EXE, &exe_path); 163 PathService::Get(content::CHILD_PROCESS_EXE, &exe_path);
163 DCHECK(!exe_path.empty()) << "Unable to get service process binary name."; 164 DCHECK(!exe_path.empty()) << "Unable to get service process binary name.";
164 scoped_ptr<base::CommandLine> command_line(new base::CommandLine(exe_path)); 165 std::unique_ptr<base::CommandLine> command_line(
166 new base::CommandLine(exe_path));
165 command_line->AppendSwitchASCII(switches::kProcessType, 167 command_line->AppendSwitchASCII(switches::kProcessType,
166 switches::kServiceProcess); 168 switches::kServiceProcess);
167 169
168 #if defined(OS_WIN) 170 #if defined(OS_WIN)
169 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument) 171 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument)
170 command_line->AppendArg(switches::kPrefetchArgumentOther); 172 command_line->AppendArg(switches::kPrefetchArgumentOther);
171 #endif // defined(OS_WIN) 173 #endif // defined(OS_WIN)
172 174
173 static const char* const kSwitchesToCopy[] = { 175 static const char* const kSwitchesToCopy[] = {
174 switches::kCloudPrintSetupProxy, 176 switches::kCloudPrintSetupProxy,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 251 }
250 252
251 bool ServiceProcessState::CreateSharedData() { 253 bool ServiceProcessState::CreateSharedData() {
252 if (version_info::GetVersionNumber().length() >= kMaxVersionStringLength) { 254 if (version_info::GetVersionNumber().length() >= kMaxVersionStringLength) {
253 NOTREACHED() << "Version string length is << " 255 NOTREACHED() << "Version string length is << "
254 << version_info::GetVersionNumber().length() 256 << version_info::GetVersionNumber().length()
255 << " which is longer than" << kMaxVersionStringLength; 257 << " which is longer than" << kMaxVersionStringLength;
256 return false; 258 return false;
257 } 259 }
258 260
259 scoped_ptr<base::SharedMemory> shared_mem_service_data( 261 std::unique_ptr<base::SharedMemory> shared_mem_service_data(
260 new base::SharedMemory()); 262 new base::SharedMemory());
261 if (!shared_mem_service_data.get()) 263 if (!shared_mem_service_data.get())
262 return false; 264 return false;
263 265
264 uint32_t alloc_size = sizeof(ServiceProcessSharedData); 266 uint32_t alloc_size = sizeof(ServiceProcessSharedData);
265 // TODO(viettrungluu): Named shared memory is deprecated (crbug.com/345734). 267 // TODO(viettrungluu): Named shared memory is deprecated (crbug.com/345734).
266 if (!shared_mem_service_data->CreateNamedDeprecated 268 if (!shared_mem_service_data->CreateNamedDeprecated
267 (GetServiceProcessSharedMemName(), true, alloc_size)) 269 (GetServiceProcessSharedMemName(), true, alloc_size))
268 return false; 270 return false;
269 271
(...skipping 10 matching lines...) Expand all
280 shared_data->service_process_pid = base::GetCurrentProcId(); 282 shared_data->service_process_pid = base::GetCurrentProcId();
281 shared_mem_service_data_.reset(shared_mem_service_data.release()); 283 shared_mem_service_data_.reset(shared_mem_service_data.release());
282 return true; 284 return true;
283 } 285 }
284 286
285 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { 287 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() {
286 return ::GetServiceProcessChannel(); 288 return ::GetServiceProcessChannel();
287 } 289 }
288 290
289 #endif // !OS_MACOSX 291 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « chrome/common/service_process_util.h ('k') | chrome/common/service_process_util_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698