OLD | NEW |
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 // MtabWatcherLinux implementation. | 5 // MtabWatcherLinux implementation. |
6 | 6 |
7 #include "components/storage_monitor/mtab_watcher_linux.h" | 7 #include "components/storage_monitor/mtab_watcher_linux.h" |
8 | 8 |
9 #include <mntent.h> | 9 #include <mntent.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 namespace storage_monitor { | 34 namespace storage_monitor { |
35 | 35 |
36 MtabWatcherLinux::MtabWatcherLinux(const base::FilePath& mtab_path, | 36 MtabWatcherLinux::MtabWatcherLinux(const base::FilePath& mtab_path, |
37 base::WeakPtr<Delegate> delegate) | 37 base::WeakPtr<Delegate> delegate) |
38 : mtab_path_(mtab_path), | 38 : mtab_path_(mtab_path), |
39 delegate_(delegate), | 39 delegate_(delegate), |
40 weak_ptr_factory_(this) { | 40 weak_ptr_factory_(this) { |
41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 41 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
42 bool ret = file_watcher_.Watch( | 42 bool ret = file_watcher_.Watch( |
43 mtab_path_, false, | 43 mtab_path_, false, |
44 base::Bind(&MtabWatcherLinux::OnFilePathChanged, | 44 base::Bind(&MtabWatcherLinux::OnFilePathChanged, |
45 weak_ptr_factory_.GetWeakPtr())); | 45 weak_ptr_factory_.GetWeakPtr())); |
46 if (!ret) { | 46 if (!ret) { |
47 LOG(ERROR) << "Adding watch for " << mtab_path_.value() << " failed"; | 47 LOG(ERROR) << "Adding watch for " << mtab_path_.value() << " failed"; |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 ReadMtab(); | 51 ReadMtab(); |
52 } | 52 } |
53 | 53 |
54 MtabWatcherLinux::~MtabWatcherLinux() { | 54 MtabWatcherLinux::~MtabWatcherLinux() { |
55 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 55 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
56 } | 56 } |
57 | 57 |
58 void MtabWatcherLinux::ReadMtab() const { | 58 void MtabWatcherLinux::ReadMtab() const { |
59 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 59 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
60 | 60 |
61 FILE* fp = setmntent(mtab_path_.value().c_str(), "r"); | 61 FILE* fp = setmntent(mtab_path_.value().c_str(), "r"); |
62 if (!fp) | 62 if (!fp) |
63 return; | 63 return; |
64 | 64 |
65 MountPointDeviceMap device_map; | 65 MountPointDeviceMap device_map; |
66 mntent entry; | 66 mntent entry; |
67 char buf[512]; | 67 char buf[512]; |
68 | 68 |
69 // We return the same device mounted to multiple locations, but hide | 69 // We return the same device mounted to multiple locations, but hide |
(...skipping 10 matching lines...) Expand all Loading... |
80 } | 80 } |
81 endmntent(fp); | 81 endmntent(fp); |
82 | 82 |
83 content::BrowserThread::PostTask( | 83 content::BrowserThread::PostTask( |
84 content::BrowserThread::UI, FROM_HERE, | 84 content::BrowserThread::UI, FROM_HERE, |
85 base::Bind(&Delegate::UpdateMtab, delegate_, device_map)); | 85 base::Bind(&Delegate::UpdateMtab, delegate_, device_map)); |
86 } | 86 } |
87 | 87 |
88 void MtabWatcherLinux::OnFilePathChanged( | 88 void MtabWatcherLinux::OnFilePathChanged( |
89 const base::FilePath& path, bool error) { | 89 const base::FilePath& path, bool error) { |
90 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 90 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
91 | 91 |
92 if (path != mtab_path_) { | 92 if (path != mtab_path_) { |
93 // This cannot happen unless FilePathWatcher is buggy. Just ignore this | 93 // This cannot happen unless FilePathWatcher is buggy. Just ignore this |
94 // notification and do nothing. | 94 // notification and do nothing. |
95 NOTREACHED(); | 95 NOTREACHED(); |
96 return; | 96 return; |
97 } | 97 } |
98 if (error) { | 98 if (error) { |
99 LOG(ERROR) << "Error watching " << mtab_path_.value(); | 99 LOG(ERROR) << "Error watching " << mtab_path_.value(); |
100 return; | 100 return; |
101 } | 101 } |
102 | 102 |
103 ReadMtab(); | 103 ReadMtab(); |
104 } | 104 } |
105 | 105 |
106 } // namespace storage_monitor | 106 } // namespace storage_monitor |
OLD | NEW |