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

Side by Side Diff: chrome/browser/devtools/devtools_file_system_indexer.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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/devtools/devtools_file_system_indexer.h" 5 #include "chrome/browser/devtools/devtools_file_system_indexer.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/file_util_proxy.h" 13 #include "base/files/file_util_proxy.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/platform_file.h" 16 #include "base/platform_file.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 19
20 using base::Bind; 20 using base::Bind;
21 using base::Callback; 21 using base::Callback;
22 using base::FileEnumerator; 22 using base::FileEnumerator;
23 using base::FilePath; 23 using base::FilePath;
24 using base::FileUtilProxy; 24 using base::FileUtilProxy;
25 using base::Time; 25 using base::Time;
26 using base::TimeDelta; 26 using base::TimeDelta;
27 using base::TimeTicks; 27 using base::TimeTicks;
28 using base::PassPlatformFile; 28 using base::PassPlatformFile;
29 using base::PlatformFile; 29 using base::PlatformFile;
30 using base::PlatformFileError;
31 using content::BrowserThread; 30 using content::BrowserThread;
32 using std::map; 31 using std::map;
33 using std::set; 32 using std::set;
34 using std::string; 33 using std::string;
35 using std::vector; 34 using std::vector;
36 35
37 namespace { 36 namespace {
38 37
39 typedef int32 Trigram; 38 typedef int32 Trigram;
40 typedef char TrigramChar; 39 typedef char TrigramChar;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 338 }
340 FilePath file_path = indexing_it_->first; 339 FilePath file_path = indexing_it_->first;
341 FileUtilProxy::CreateOrOpen( 340 FileUtilProxy::CreateOrOpen(
342 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), 341 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
343 file_path, 342 file_path,
344 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, 343 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
345 Bind(&FileSystemIndexingJob::StartFileIndexing, this)); 344 Bind(&FileSystemIndexingJob::StartFileIndexing, this));
346 } 345 }
347 346
348 void DevToolsFileSystemIndexer::FileSystemIndexingJob::StartFileIndexing( 347 void DevToolsFileSystemIndexer::FileSystemIndexingJob::StartFileIndexing(
349 PlatformFileError error, 348 base::File::Error error,
350 PassPlatformFile pass_file, 349 PassPlatformFile pass_file,
351 bool) { 350 bool) {
352 if (error != base::PLATFORM_FILE_OK) { 351 if (error != base::File::FILE_OK) {
353 current_file_ = base::kInvalidPlatformFileValue; 352 current_file_ = base::kInvalidPlatformFileValue;
354 FinishFileIndexing(false); 353 FinishFileIndexing(false);
355 return; 354 return;
356 } 355 }
357 current_file_ = pass_file.ReleaseValue(); 356 current_file_ = pass_file.ReleaseValue();
358 current_file_offset_ = 0; 357 current_file_offset_ = 0;
359 current_trigrams_.clear(); 358 current_trigrams_.clear();
360 std::fill(current_trigrams_set_.begin(), current_trigrams_set_.end(), false); 359 std::fill(current_trigrams_set_.begin(), current_trigrams_set_.end(), false);
361 ReadFromFile(); 360 ReadFromFile();
362 } 361 }
363 362
364 void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReadFromFile() { 363 void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReadFromFile() {
365 if (stopped_) { 364 if (stopped_) {
366 CloseFile(); 365 CloseFile();
367 return; 366 return;
368 } 367 }
369 FileUtilProxy::Read( 368 FileUtilProxy::Read(
370 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), 369 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
371 current_file_, 370 current_file_,
372 current_file_offset_, 371 current_file_offset_,
373 kMaxReadLength, 372 kMaxReadLength,
374 Bind(&FileSystemIndexingJob::OnRead, this)); 373 Bind(&FileSystemIndexingJob::OnRead, this));
375 } 374 }
376 375
377 void DevToolsFileSystemIndexer::FileSystemIndexingJob::OnRead( 376 void DevToolsFileSystemIndexer::FileSystemIndexingJob::OnRead(
378 PlatformFileError error, 377 base::File::Error error,
379 const char* data, 378 const char* data,
380 int bytes_read) { 379 int bytes_read) {
381 if (error != base::PLATFORM_FILE_OK) { 380 if (error != base::File::FILE_OK) {
382 FinishFileIndexing(false); 381 FinishFileIndexing(false);
383 return; 382 return;
384 } 383 }
385 384
386 if (!bytes_read || bytes_read < 3) { 385 if (!bytes_read || bytes_read < 3) {
387 FinishFileIndexing(true); 386 FinishFileIndexing(true);
388 return; 387 return;
389 } 388 }
390 389
391 size_t size = static_cast<size_t>(bytes_read); 390 size_t size = static_cast<size_t>(bytes_read);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void DevToolsFileSystemIndexer::FileSystemIndexingJob::CloseFile() { 427 void DevToolsFileSystemIndexer::FileSystemIndexingJob::CloseFile() {
429 if (current_file_ != base::kInvalidPlatformFileValue) { 428 if (current_file_ != base::kInvalidPlatformFileValue) {
430 FileUtilProxy::Close( 429 FileUtilProxy::Close(
431 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), 430 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
432 current_file_, 431 current_file_,
433 Bind(&FileSystemIndexingJob::CloseCallback, this)); 432 Bind(&FileSystemIndexingJob::CloseCallback, this));
434 } 433 }
435 } 434 }
436 435
437 void DevToolsFileSystemIndexer::FileSystemIndexingJob::CloseCallback( 436 void DevToolsFileSystemIndexer::FileSystemIndexingJob::CloseCallback(
438 PlatformFileError error) {} 437 base::File::Error error) {}
439 438
440 void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReportWorked() { 439 void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReportWorked() {
441 TimeTicks current_time = TimeTicks::Now(); 440 TimeTicks current_time = TimeTicks::Now();
442 bool should_send_worked_nitification = true; 441 bool should_send_worked_nitification = true;
443 if (!last_worked_notification_time_.is_null()) { 442 if (!last_worked_notification_time_.is_null()) {
444 TimeDelta delta = current_time - last_worked_notification_time_; 443 TimeDelta delta = current_time - last_worked_notification_time_;
445 if (delta.InMilliseconds() < kMinTimeoutBetweenWorkedNitification) 444 if (delta.InMilliseconds() < kMinTimeoutBetweenWorkedNitification)
446 should_send_worked_nitification = false; 445 should_send_worked_nitification = false;
447 } 446 }
448 ++files_indexed_; 447 ++files_indexed_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 vector<FilePath> file_paths = g_trigram_index.Get().Search(query); 502 vector<FilePath> file_paths = g_trigram_index.Get().Search(query);
504 vector<string> result; 503 vector<string> result;
505 FilePath path = FilePath::FromUTF8Unsafe(file_system_path); 504 FilePath path = FilePath::FromUTF8Unsafe(file_system_path);
506 vector<FilePath>::const_iterator it = file_paths.begin(); 505 vector<FilePath>::const_iterator it = file_paths.begin();
507 for (; it != file_paths.end(); ++it) { 506 for (; it != file_paths.end(); ++it) {
508 if (path.IsParent(*it)) 507 if (path.IsParent(*it))
509 result.push_back(it->AsUTF8Unsafe()); 508 result.push_back(it->AsUTF8Unsafe());
510 } 509 }
511 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, Bind(callback, result)); 510 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, Bind(callback, result));
512 } 511 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698