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

Side by Side Diff: chrome/browser/supervised_user/experimental/supervised_user_blacklist.cc

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
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/supervised_user/experimental/supervised_user_blacklist. h" 5 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist. h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <fstream> 9 #include <fstream>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/memory_mapped_file.h" 12 #include "base/files/memory_mapped_file.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 using content::BrowserThread; 16 using content::BrowserThread;
17 17
18 namespace { 18 namespace {
19 19
20 scoped_ptr<std::vector<SupervisedUserBlacklist::Hash> > 20 scoped_ptr<std::vector<SupervisedUserBlacklist::Hash> >
21 ReadFromBinaryFileOnFileThread(const base::FilePath& path) { 21 ReadFromBinaryFileOnFileThread(const base::FilePath& path) {
22 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 22 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
23 23
24 scoped_ptr<std::vector<SupervisedUserBlacklist::Hash> > host_hashes( 24 scoped_ptr<std::vector<SupervisedUserBlacklist::Hash> > host_hashes(
25 new std::vector<SupervisedUserBlacklist::Hash>); 25 new std::vector<SupervisedUserBlacklist::Hash>);
26 26
27 base::MemoryMappedFile file; 27 base::MemoryMappedFile file;
28 file.Initialize(path); 28 file.Initialize(path);
29 if (!file.IsValid()) 29 if (!file.IsValid())
30 return host_hashes.Pass(); 30 return host_hashes;
31 31
32 size_t size = file.length(); 32 size_t size = file.length();
33 if (size <= 0 || size % base::kSHA1Length != 0) 33 if (size <= 0 || size % base::kSHA1Length != 0)
34 return host_hashes.Pass(); 34 return host_hashes;
35 35
36 size_t hash_count = size / base::kSHA1Length; 36 size_t hash_count = size / base::kSHA1Length;
37 host_hashes->resize(hash_count); 37 host_hashes->resize(hash_count);
38 38
39 for (size_t i = 0; i < hash_count; i++) { 39 for (size_t i = 0; i < hash_count; i++) {
40 memcpy((*host_hashes.get())[i].data, 40 memcpy((*host_hashes.get())[i].data,
41 file.data() + i * base::kSHA1Length, 41 file.data() + i * base::kSHA1Length,
42 base::kSHA1Length); 42 base::kSHA1Length);
43 } 43 }
44 44
45 std::sort(host_hashes->begin(), host_hashes->end()); 45 std::sort(host_hashes->begin(), host_hashes->end());
46 46
47 return host_hashes.Pass(); 47 return host_hashes;
48 } 48 }
49 49
50 } // namespace 50 } // namespace
51 51
52 SupervisedUserBlacklist::Hash::Hash(const std::string& host) { 52 SupervisedUserBlacklist::Hash::Hash(const std::string& host) {
53 const unsigned char* host_bytes = 53 const unsigned char* host_bytes =
54 reinterpret_cast<const unsigned char*>(host.c_str()); 54 reinterpret_cast<const unsigned char*>(host.c_str());
55 base::SHA1HashBytes(host_bytes, host.length(), data); 55 base::SHA1HashBytes(host_bytes, host.length(), data);
56 } 56 }
57 57
(...skipping 28 matching lines...) Expand all
86 86
87 void SupervisedUserBlacklist::OnReadFromFileCompleted( 87 void SupervisedUserBlacklist::OnReadFromFileCompleted(
88 const base::Closure& done_callback, 88 const base::Closure& done_callback,
89 scoped_ptr<std::vector<Hash> > host_hashes) { 89 scoped_ptr<std::vector<Hash> > host_hashes) {
90 host_hashes_.swap(*host_hashes); 90 host_hashes_.swap(*host_hashes);
91 LOG_IF(WARNING, host_hashes_.empty()) << "Got empty blacklist"; 91 LOG_IF(WARNING, host_hashes_.empty()) << "Got empty blacklist";
92 92
93 if (!done_callback.is_null()) 93 if (!done_callback.is_null())
94 done_callback.Run(); 94 done_callback.Run();
95 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698