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

Side by Side Diff: components/offline_pages/offline_page_test_archiver.cc

Issue 1521193002: [Offline pages] Refactor URL conversions from TabAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback, updating tests, moving functions to a static class Created 5 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/offline_pages/offline_page_test_archiver.h" 5 #include "components/offline_pages/offline_page_test_archiver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 12
13 namespace offline_pages { 13 namespace offline_pages {
14 namespace {
15
16 base::FilePath CreateArchiveFile(const base::FilePath& archives_dir,
jianli 2015/12/16 23:08:08 Since this is only used in one place and the logic
fgorski 2015/12/17 19:00:14 Done.
17 const base::FilePath& file_name) {
18 base::FilePath file_path(archives_dir.Append(file_name));
19 base::File file(file_path, base::File::FLAG_OPEN_ALWAYS);
20 return file_path;
21 }
22
23 } // namespace
14 24
15 OfflinePageTestArchiver::OfflinePageTestArchiver( 25 OfflinePageTestArchiver::OfflinePageTestArchiver(
16 Observer* observer, 26 Observer* observer,
17 const GURL& url, 27 const GURL& url,
18 ArchiverResult result, 28 ArchiverResult result,
19 int64 size_to_report, 29 int64 size_to_report,
20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 30 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
21 : observer_(observer), 31 : observer_(observer),
22 url_(url), 32 url_(url),
23 result_(result), 33 result_(result),
(...skipping 12 matching lines...) Expand all
36 create_archive_called_ = true; 46 create_archive_called_ = true;
37 callback_ = callback; 47 callback_ = callback;
38 archives_dir_ = archives_dir; 48 archives_dir_ = archives_dir;
39 if (!delayed_) 49 if (!delayed_)
40 CompleteCreateArchive(); 50 CompleteCreateArchive();
41 } 51 }
42 52
43 void OfflinePageTestArchiver::CompleteCreateArchive() { 53 void OfflinePageTestArchiver::CompleteCreateArchive() {
44 DCHECK(!callback_.is_null()); 54 DCHECK(!callback_.is_null());
45 base::FilePath archive_path; 55 base::FilePath archive_path;
46 ASSERT_TRUE(base::CreateTemporaryFileInDir(archives_dir_, &archive_path)); 56 if (file_name_.empty())
jianli 2015/12/16 23:08:08 nit: add brackets
fgorski 2015/12/17 19:00:14 Done.
57 ASSERT_TRUE(base::CreateTemporaryFileInDir(archives_dir_, &archive_path));
58 else {
59 archive_path = CreateArchiveFile(archives_dir_, file_name_);
60 }
47 observer_->SetLastPathCreatedByArchiver(archive_path); 61 observer_->SetLastPathCreatedByArchiver(archive_path);
48 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, this, result_, url_, 62 task_runner_->PostTask(FROM_HERE, base::Bind(callback_, this, result_, url_,
49 archive_path, size_to_report_)); 63 archive_path, size_to_report_));
50 } 64 }
51 65
52 } // namespace offline_pages 66 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698