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

Side by Side Diff: chrome/browser/extensions/api/log_private/log_private_api_chromeos.cc

Issue 2320703002: Remove calls to IsRunningSequenceOnCurrentThread() from log_private_api_chromeos.cc (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | 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 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/extensions/api/log_private/log_private_api.h" 5 #include "chrome/browser/extensions/api/log_private/log_private_api.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const int kNetLogEventDelayMilliseconds = 100; 54 const int kNetLogEventDelayMilliseconds = 100;
55 55
56 // Gets sequenced task runner for file specific calls within this API. 56 // Gets sequenced task runner for file specific calls within this API.
57 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() { 57 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() {
58 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 58 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
59 return pool->GetSequencedTaskRunnerWithShutdownBehavior( 59 return pool->GetSequencedTaskRunnerWithShutdownBehavior(
60 pool->GetNamedSequenceToken(FileResource::kSequenceToken), 60 pool->GetNamedSequenceToken(FileResource::kSequenceToken),
61 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 61 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
62 } 62 }
63 63
64 #if DCHECK_IS_ON()
65 base::LazyInstance<base::SequenceChecker>::Leaky
66 g_file_resource_sequence_checker = LAZY_INSTANCE_INITIALIZER;
67 #endif
68
64 // Checks if we are running on sequenced task runner thread. 69 // Checks if we are running on sequenced task runner thread.
65 bool IsRunningOnSequenceThread() { 70 void AssertCurrentlyOnFileResourceSequence() {
66 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); 71 #if DCHECK_IS_ON()
67 return pool->IsRunningSequenceOnCurrentThread( 72 DCHECK(g_file_resource_sequence_checker.Get().CalledOnValidSequence());
68 pool->GetNamedSequenceToken(FileResource::kSequenceToken)); 73 #endif
69 } 74 }
70 75
71 std::unique_ptr<LogParser> CreateLogParser(const std::string& log_type) { 76 std::unique_ptr<LogParser> CreateLogParser(const std::string& log_type) {
72 if (log_type == "syslog") 77 if (log_type == "syslog")
73 return std::unique_ptr<LogParser>(new SyslogParser()); 78 return std::unique_ptr<LogParser>(new SyslogParser());
74 // TODO(shinfan): Add more parser here 79 // TODO(shinfan): Add more parser here
75 80
76 NOTREACHED() << "Invalid log type: " << log_type; 81 NOTREACHED() << "Invalid log type: " << log_type;
77 return std::unique_ptr<LogParser>(); 82 return std::unique_ptr<LogParser>();
78 } 83 }
(...skipping 28 matching lines...) Expand all
107 } 112 }
108 113
109 // Removes direcotry content of |logs_dumps| and |app_logs_dir| (only for the 114 // Removes direcotry content of |logs_dumps| and |app_logs_dir| (only for the
110 // primary profile). 115 // primary profile).
111 void CleanUpLeftoverLogs(bool is_primary_profile, 116 void CleanUpLeftoverLogs(bool is_primary_profile,
112 const base::FilePath& app_logs_dir, 117 const base::FilePath& app_logs_dir,
113 const base::FilePath& logs_dumps) { 118 const base::FilePath& logs_dumps) {
114 LOG(WARNING) << "Deleting " << app_logs_dir.value(); 119 LOG(WARNING) << "Deleting " << app_logs_dir.value();
115 LOG(WARNING) << "Deleting " << logs_dumps.value(); 120 LOG(WARNING) << "Deleting " << logs_dumps.value();
116 121
117 DCHECK(IsRunningOnSequenceThread()); 122 AssertCurrentlyOnFileResourceSequence();
118 base::DeleteFile(logs_dumps, true); 123 base::DeleteFile(logs_dumps, true);
119 124
120 // App-specific logs are stored in /home/chronos/user/log/apps directory that 125 // App-specific logs are stored in /home/chronos/user/log/apps directory that
121 // is shared between all profiles in multi-profile case. We should not 126 // is shared between all profiles in multi-profile case. We should not
122 // nuke it for non-primary profiles. 127 // nuke it for non-primary profiles.
123 if (!is_primary_profile) 128 if (!is_primary_profile)
124 return; 129 return;
125 130
126 base::DeleteFile(app_logs_dir, true); 131 base::DeleteFile(app_logs_dir, true);
127 } 132 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 MaybeStopNetInternalLogging(closure); 191 MaybeStopNetInternalLogging(closure);
187 } 192 }
188 193
189 void LogPrivateAPI::StopAllWatches(const std::string& extension_id, 194 void LogPrivateAPI::StopAllWatches(const std::string& extension_id,
190 const base::Closure& closure) { 195 const base::Closure& closure) {
191 StopNetInternalsWatch(extension_id, closure); 196 StopNetInternalsWatch(extension_id, closure);
192 } 197 }
193 198
194 void LogPrivateAPI::RegisterTempFile(const std::string& owner_extension_id, 199 void LogPrivateAPI::RegisterTempFile(const std::string& owner_extension_id,
195 const base::FilePath& file_path) { 200 const base::FilePath& file_path) {
196 if (!IsRunningOnSequenceThread()) { 201 GetSequencedTaskRunner()->PostTask(
197 GetSequencedTaskRunner()->PostTask( 202 FROM_HERE, base::Bind(
198 FROM_HERE, 203 [](decltype(&log_file_resources_) log_file_resources,
199 base::Bind(&LogPrivateAPI::RegisterTempFile, 204 const std::string& owner_extension_id,
200 base::Unretained(this), 205 const base::FilePath& file_path) {
201 owner_extension_id, 206 log_file_resources->Add(
202 file_path)); 207 new FileResource(owner_extension_id, file_path));
203 return; 208 },
204 } 209 base::Unretained(&log_file_resources_), owner_extension_id,
205 210 file_path));
206 log_file_resources_.Add(new FileResource(owner_extension_id, file_path));
207 } 211 }
208 212
209 static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> > 213 static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> >
210 g_factory = LAZY_INSTANCE_INITIALIZER; 214 g_factory = LAZY_INSTANCE_INITIALIZER;
211 215
212 // static 216 // static
213 BrowserContextKeyedAPIFactory<LogPrivateAPI>* 217 BrowserContextKeyedAPIFactory<LogPrivateAPI>*
214 LogPrivateAPI::GetFactoryInstance() { 218 LogPrivateAPI::GetFactoryInstance() {
215 return g_factory.Pointer(); 219 return g_factory.Pointer();
216 } 220 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 std::unique_ptr<Event> event( 256 std::unique_ptr<Event> event(
253 new Event(::extensions::events::LOG_PRIVATE_ON_CAPTURED_EVENTS, 257 new Event(::extensions::events::LOG_PRIVATE_ON_CAPTURED_EVENTS,
254 ::events::kOnCapturedEvents, std::move(event_args))); 258 ::events::kOnCapturedEvents, std::move(event_args)));
255 EventRouter::Get(browser_context_) 259 EventRouter::Get(browser_context_)
256 ->DispatchEventToExtension(*ix, std::move(event)); 260 ->DispatchEventToExtension(*ix, std::move(event));
257 } 261 }
258 } 262 }
259 263
260 void LogPrivateAPI::CreateTempNetLogFile(const std::string& owner_extension_id, 264 void LogPrivateAPI::CreateTempNetLogFile(const std::string& owner_extension_id,
261 base::ScopedFILE* file) { 265 base::ScopedFILE* file) {
262 DCHECK(IsRunningOnSequenceThread()); 266 AssertCurrentlyOnFileResourceSequence();
263 267
264 // Create app-specific subdirectory in session logs folder. 268 // Create app-specific subdirectory in session logs folder.
265 base::FilePath app_log_dir = GetAppLogDirectory().Append(owner_extension_id); 269 base::FilePath app_log_dir = GetAppLogDirectory().Append(owner_extension_id);
266 if (!base::DirectoryExists(app_log_dir)) { 270 if (!base::DirectoryExists(app_log_dir)) {
267 if (!base::CreateDirectory(app_log_dir)) { 271 if (!base::CreateDirectory(app_log_dir)) {
268 LOG(ERROR) << "Could not create dir " << app_log_dir.value(); 272 LOG(ERROR) << "Could not create dir " << app_log_dir.value();
269 return; 273 return;
270 } 274 }
271 } 275 }
272 276
273 base::FilePath file_path = app_log_dir.Append(kLogFileNameBase); 277 base::FilePath file_path = app_log_dir.Append(kLogFileNameBase);
274 file_path = logging::GenerateTimestampedName(file_path, base::Time::Now()); 278 file_path = logging::GenerateTimestampedName(file_path, base::Time::Now());
275 FILE* file_ptr = fopen(file_path.value().c_str(), "w"); 279 FILE* file_ptr = fopen(file_path.value().c_str(), "w");
276 if (file_ptr == nullptr) { 280 if (file_ptr == nullptr) {
277 LOG(ERROR) << "Could not open " << file_path.value(); 281 LOG(ERROR) << "Could not open " << file_path.value();
278 return; 282 return;
279 } 283 }
280 284
281 RegisterTempFile(owner_extension_id, file_path); 285 RegisterTempFile(owner_extension_id, file_path);
Reilly Grant (use Gerrit) 2016/09/07 18:00:05 I believe this change is going to change the seman
fdoray 2016/09/07 20:17:42 Right. Fixed in latest patch set.
282 return file->reset(file_ptr); 286 return file->reset(file_ptr);
283 } 287 }
284 288
285 void LogPrivateAPI::StartObservingNetEvents( 289 void LogPrivateAPI::StartObservingNetEvents(
286 IOThread* io_thread, 290 IOThread* io_thread,
287 base::ScopedFILE* file) { 291 base::ScopedFILE* file) {
288 DCHECK_CURRENTLY_ON(BrowserThread::IO); 292 DCHECK_CURRENTLY_ON(BrowserThread::IO);
289 if (!file->get()) 293 if (!file->get())
290 return; 294 return;
291 295
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 entry->SetBoolean("isDirectory", false); 542 entry->SetBoolean("isDirectory", false);
539 base::ListValue* entry_list = new base::ListValue(); 543 base::ListValue* entry_list = new base::ListValue();
540 entry_list->Append(entry); 544 entry_list->Append(entry);
541 response->Set("entries", entry_list); 545 response->Set("entries", entry_list);
542 response->SetBoolean("multiple", false); 546 response->SetBoolean("multiple", false);
543 SetResult(std::move(response)); 547 SetResult(std::move(response));
544 SendResponse(succeeded); 548 SendResponse(succeeded);
545 } 549 }
546 550
547 } // namespace extensions 551 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698