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

Side by Side Diff: chrome/common/important_file_writer.cc

Issue 6627060: ImportantFileWriter: check return value of PostTask... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/common/important_file_writer.h" 5 #include "chrome/common/important_file_writer.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 DCHECK(CalledOnValidThread()); 99 DCHECK(CalledOnValidThread());
100 return timer_.IsRunning(); 100 return timer_.IsRunning();
101 } 101 }
102 102
103 void ImportantFileWriter::WriteNow(const std::string& data) { 103 void ImportantFileWriter::WriteNow(const std::string& data) {
104 DCHECK(CalledOnValidThread()); 104 DCHECK(CalledOnValidThread());
105 105
106 if (HasPendingWrite()) 106 if (HasPendingWrite())
107 timer_.Stop(); 107 timer_.Stop();
108 108
109 // TODO(sanjeevr): Add a DCHECK for the return value of PostTask. 109 if (!file_message_loop_proxy_->PostTask(FROM_HERE,
110 // (Some tests fail if we add the DCHECK and they need to be fixed first). 110 new WriteToDiskTask(path_, data))) {
111 file_message_loop_proxy_->PostTask(FROM_HERE, 111 // Posting the task to background message loop is not expected
112 new WriteToDiskTask(path_, data)); 112 // to fail, but if it does, avoid loosing data and just hit the disk
sanjeevr 2011/03/08 19:42:05 Spelling Nit: loosing => losing
Paweł Hajdan Jr. 2011/03/09 09:09:22 Done.
113 // on the current thread.
114 // TODO(phajdan.jr): Fix test failures on Win and enable code below.
115 #if !defined(OS_WIN)
116 NOTREACHED();
117
118 WriteToDiskTask write_task(path_, data);
119 write_task.Run();
120 #endif
121 }
113 } 122 }
114 123
115 void ImportantFileWriter::ScheduleWrite(DataSerializer* serializer) { 124 void ImportantFileWriter::ScheduleWrite(DataSerializer* serializer) {
116 DCHECK(CalledOnValidThread()); 125 DCHECK(CalledOnValidThread());
117 126
118 DCHECK(serializer); 127 DCHECK(serializer);
119 serializer_ = serializer; 128 serializer_ = serializer;
120 129
121 if (!MessageLoop::current()) { 130 if (!MessageLoop::current()) {
122 // Happens in unit tests. 131 // Happens in unit tests.
(...skipping 11 matching lines...) Expand all
134 DCHECK(serializer_); 143 DCHECK(serializer_);
135 std::string data; 144 std::string data;
136 if (serializer_->SerializeData(&data)) { 145 if (serializer_->SerializeData(&data)) {
137 WriteNow(data); 146 WriteNow(data);
138 } else { 147 } else {
139 LOG(WARNING) << "failed to serialize data to be saved in " 148 LOG(WARNING) << "failed to serialize data to be saved in "
140 << path_.value(); 149 << path_.value();
141 } 150 }
142 serializer_ = NULL; 151 serializer_ = NULL;
143 } 152 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc ('k') | chrome/test/browser_with_test_window_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698