Index: chrome/common/important_file_writer.cc |
diff --git a/chrome/common/important_file_writer.cc b/chrome/common/important_file_writer.cc |
index f5c5fc115c1dcee81bc86f71d7c32235b8264c76..076689bca9cce6a7fa852815c236c13943aeab53 100644 |
--- a/chrome/common/important_file_writer.cc |
+++ b/chrome/common/important_file_writer.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -16,6 +16,8 @@ |
#include "base/task.h" |
#include "base/threading/thread.h" |
#include "base/time.h" |
+#include "content/browser/browser_thread.h" |
+#include "content/common/notification_service.h" |
using base::TimeDelta; |
@@ -23,11 +25,37 @@ namespace { |
const int kDefaultCommitIntervalMs = 10000; |
+class CommitNotificationTask: public Task { |
+ public: |
+ CommitNotificationTask(bool success, NotificationSource source) |
+ : success_(success), |
+ source_(source) { |
+ } |
+ |
+ virtual void Run() { |
+ // At this moment we do not send notification in case of failure but we may |
+ // want to send it including additional information in details. |
+ if (success_ && NotificationService::current()) { |
+ NotificationService::current()->Notify( |
+ NotificationType::PREF_COMMITTED, |
+ source_, |
+ NotificationService::NoDetails()); |
+ } |
+ } |
+ |
+ private: |
+ bool success_; |
+ NotificationSource source_; |
+}; |
+ |
class WriteToDiskTask : public Task { |
public: |
- WriteToDiskTask(const FilePath& path, const std::string& data) |
+ WriteToDiskTask(const FilePath& path, |
+ const std::string& data, |
+ NotificationSource source) |
: path_(path), |
- data_(data) { |
+ data_(data), |
+ source_(source) { |
} |
virtual void Run() { |
@@ -61,6 +89,11 @@ class WriteToDiskTask : public Task { |
file_util::Delete(tmp_file_path, false); |
return; |
} |
+#if defined(OS_CHROMEOS) |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ new CommitNotificationTask(true, source_)); |
+#endif |
} |
private: |
@@ -71,6 +104,7 @@ class WriteToDiskTask : public Task { |
const FilePath path_; |
const std::string data_; |
+ const NotificationSource source_; |
DISALLOW_COPY_AND_ASSIGN(WriteToDiskTask); |
}; |
@@ -83,7 +117,8 @@ ImportantFileWriter::ImportantFileWriter( |
file_message_loop_proxy_(file_message_loop_proxy), |
serializer_(NULL), |
commit_interval_(TimeDelta::FromMilliseconds( |
- kDefaultCommitIntervalMs)) { |
+ kDefaultCommitIntervalMs)), |
+ source_(NotificationService::AllSources()) { |
DCHECK(CalledOnValidThread()); |
DCHECK(file_message_loop_proxy_.get()); |
} |
@@ -106,14 +141,14 @@ void ImportantFileWriter::WriteNow(const std::string& data) { |
if (HasPendingWrite()) |
timer_.Stop(); |
- if (!file_message_loop_proxy_->PostTask(FROM_HERE, |
- new WriteToDiskTask(path_, data))) { |
+ if (!file_message_loop_proxy_->PostTask( |
+ FROM_HERE, new WriteToDiskTask(path_, data, source_))) { |
// Posting the task to background message loop is not expected |
// to fail, but if it does, avoid losing data and just hit the disk |
// on the current thread. |
NOTREACHED(); |
- WriteToDiskTask write_task(path_, data); |
+ WriteToDiskTask write_task(path_, data, source_); |
write_task.Run(); |
} |
} |