OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bookmarks/bookmark_html_writer.h" | 5 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 Write(kFolderChildrenEnd); | 145 Write(kFolderChildrenEnd); |
146 Write(kNewline); | 146 Write(kNewline); |
147 // File stream close is forced so that unit test could read it. | 147 // File stream close is forced so that unit test could read it. |
148 file_stream_.CloseSync(); | 148 file_stream_.CloseSync(); |
149 | 149 |
150 NotifyOnFinish(); | 150 NotifyOnFinish(); |
151 } | 151 } |
152 | 152 |
153 private: | 153 private: |
| 154 friend class base::RefCountedThreadSafe<Writer>; |
| 155 |
154 // Types of text being written out. The type dictates how the text is | 156 // Types of text being written out. The type dictates how the text is |
155 // escaped. | 157 // escaped. |
156 enum TextType { | 158 enum TextType { |
157 // The text is the value of an html attribute, eg foo in | 159 // The text is the value of an html attribute, eg foo in |
158 // <a href="foo">. | 160 // <a href="foo">. |
159 ATTRIBUTE_VALUE, | 161 ATTRIBUTE_VALUE, |
160 | 162 |
161 // Actual content, eg foo in <h1>foo</h2>. | 163 // Actual content, eg foo in <h1>foo</h2>. |
162 CONTENT | 164 CONTENT |
163 }; | 165 }; |
164 | 166 |
| 167 ~Writer() {} |
| 168 |
165 // Opens the file, returning true on success. | 169 // Opens the file, returning true on success. |
166 bool OpenFile() { | 170 bool OpenFile() { |
167 int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; | 171 int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; |
168 return (file_stream_.OpenSync(path_, flags) == net::OK); | 172 return (file_stream_.OpenSync(path_, flags) == net::OK); |
169 } | 173 } |
170 | 174 |
171 // Increments the indent. | 175 // Increments the indent. |
172 void IncrementIndent() { | 176 void IncrementIndent() { |
173 indent_.resize(indent_.size() + kIndentSize, ' '); | 177 indent_.resize(indent_.size() + kIndentSize, ' '); |
174 } | 178 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // BookmarkModel isn't thread safe (nor would we want to lock it down | 493 // BookmarkModel isn't thread safe (nor would we want to lock it down |
490 // for the duration of the write), as such we make a copy of the | 494 // for the duration of the write), as such we make a copy of the |
491 // BookmarkModel using BookmarkCodec then write from that. | 495 // BookmarkModel using BookmarkCodec then write from that. |
492 if (fetcher == NULL) { | 496 if (fetcher == NULL) { |
493 fetcher = new BookmarkFaviconFetcher(profile, path, observer); | 497 fetcher = new BookmarkFaviconFetcher(profile, path, observer); |
494 fetcher->ExportBookmarks(); | 498 fetcher->ExportBookmarks(); |
495 } | 499 } |
496 } | 500 } |
497 | 501 |
498 } // namespace bookmark_html_writer | 502 } // namespace bookmark_html_writer |
OLD | NEW |