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

Side by Side Diff: content/browser/download/drag_download_util.cc

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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) 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 "content/browser/download/drag_download_util.h" 5 #include "content/browser/download/drag_download_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "net/base/file_stream.h" 19 #include "net/base/file_stream.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 21
22 using net::FileStream; 22 using net::FileStream;
23 23
24 namespace content { 24 namespace content {
25 25
26 bool ParseDownloadMetadata(const string16& metadata, 26 bool ParseDownloadMetadata(const string16& metadata,
27 string16* mime_type, 27 string16* mime_type,
28 FilePath* file_name, 28 base::FilePath* file_name,
29 GURL* url) { 29 GURL* url) {
30 const char16 separator = L':'; 30 const char16 separator = L':';
31 31
32 size_t mime_type_end_pos = metadata.find(separator); 32 size_t mime_type_end_pos = metadata.find(separator);
33 if (mime_type_end_pos == string16::npos) 33 if (mime_type_end_pos == string16::npos)
34 return false; 34 return false;
35 35
36 size_t file_name_end_pos = metadata.find(separator, mime_type_end_pos + 1); 36 size_t file_name_end_pos = metadata.find(separator, mime_type_end_pos + 1);
37 if (file_name_end_pos == string16::npos) 37 if (file_name_end_pos == string16::npos)
38 return false; 38 return false;
39 39
40 GURL parsed_url = GURL(metadata.substr(file_name_end_pos + 1)); 40 GURL parsed_url = GURL(metadata.substr(file_name_end_pos + 1));
41 if (!parsed_url.is_valid()) 41 if (!parsed_url.is_valid())
42 return false; 42 return false;
43 43
44 if (mime_type) 44 if (mime_type)
45 *mime_type = metadata.substr(0, mime_type_end_pos); 45 *mime_type = metadata.substr(0, mime_type_end_pos);
46 if (file_name) { 46 if (file_name) {
47 string16 file_name_str = metadata.substr( 47 string16 file_name_str = metadata.substr(
48 mime_type_end_pos + 1, file_name_end_pos - mime_type_end_pos - 1); 48 mime_type_end_pos + 1, file_name_end_pos - mime_type_end_pos - 1);
49 #if defined(OS_WIN) 49 #if defined(OS_WIN)
50 *file_name = FilePath(file_name_str); 50 *file_name = base::FilePath(file_name_str);
51 #else 51 #else
52 *file_name = FilePath(UTF16ToUTF8(file_name_str)); 52 *file_name = base::FilePath(UTF16ToUTF8(file_name_str));
53 #endif 53 #endif
54 } 54 }
55 if (url) 55 if (url)
56 *url = parsed_url; 56 *url = parsed_url;
57 57
58 return true; 58 return true;
59 } 59 }
60 60
61 FileStream* CreateFileStreamForDrop(FilePath* file_path, net::NetLog* net_log) { 61 FileStream* CreateFileStreamForDrop(base::FilePath* file_path,
62 net::NetLog* net_log) {
62 DCHECK(file_path && !file_path->empty()); 63 DCHECK(file_path && !file_path->empty());
63 64
64 scoped_ptr<FileStream> file_stream(new FileStream(net_log)); 65 scoped_ptr<FileStream> file_stream(new FileStream(net_log));
65 const int kMaxSeq = 99; 66 const int kMaxSeq = 99;
66 for (int seq = 0; seq <= kMaxSeq; seq++) { 67 for (int seq = 0; seq <= kMaxSeq; seq++) {
67 FilePath new_file_path; 68 base::FilePath new_file_path;
68 if (seq == 0) { 69 if (seq == 0) {
69 new_file_path = *file_path; 70 new_file_path = *file_path;
70 } else { 71 } else {
71 #if defined(OS_WIN) 72 #if defined(OS_WIN)
72 string16 suffix = ASCIIToUTF16("-") + base::IntToString16(seq); 73 string16 suffix = ASCIIToUTF16("-") + base::IntToString16(seq);
73 #else 74 #else
74 std::string suffix = std::string("-") + base::IntToString(seq); 75 std::string suffix = std::string("-") + base::IntToString(seq);
75 #endif 76 #endif
76 new_file_path = file_path->InsertBeforeExtension(suffix); 77 new_file_path = file_path->InsertBeforeExtension(suffix);
77 } 78 }
(...skipping 12 matching lines...) Expand all
90 } 91 }
91 92
92 return NULL; 93 return NULL;
93 } 94 }
94 95
95 PromiseFileFinalizer::PromiseFileFinalizer( 96 PromiseFileFinalizer::PromiseFileFinalizer(
96 DragDownloadFile* drag_file_downloader) 97 DragDownloadFile* drag_file_downloader)
97 : drag_file_downloader_(drag_file_downloader) { 98 : drag_file_downloader_(drag_file_downloader) {
98 } 99 }
99 100
100 void PromiseFileFinalizer::OnDownloadCompleted(const FilePath& file_path) { 101 void PromiseFileFinalizer::OnDownloadCompleted(
102 const base::FilePath& file_path) {
101 BrowserThread::PostTask( 103 BrowserThread::PostTask(
102 BrowserThread::UI, FROM_HERE, 104 BrowserThread::UI, FROM_HERE,
103 base::Bind(&PromiseFileFinalizer::Cleanup, this)); 105 base::Bind(&PromiseFileFinalizer::Cleanup, this));
104 } 106 }
105 107
106 void PromiseFileFinalizer::OnDownloadAborted() { 108 void PromiseFileFinalizer::OnDownloadAborted() {
107 BrowserThread::PostTask( 109 BrowserThread::PostTask(
108 BrowserThread::UI, FROM_HERE, 110 BrowserThread::UI, FROM_HERE,
109 base::Bind(&PromiseFileFinalizer::Cleanup, this)); 111 base::Bind(&PromiseFileFinalizer::Cleanup, this));
110 } 112 }
111 113
112 PromiseFileFinalizer::~PromiseFileFinalizer() {} 114 PromiseFileFinalizer::~PromiseFileFinalizer() {}
113 115
114 void PromiseFileFinalizer::Cleanup() { 116 void PromiseFileFinalizer::Cleanup() {
115 if (drag_file_downloader_.get()) 117 if (drag_file_downloader_.get())
116 drag_file_downloader_ = NULL; 118 drag_file_downloader_ = NULL;
117 } 119 }
118 120
119 } // namespace content 121 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/drag_download_file_browsertest.cc ('k') | content/browser/download/file_metadata_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698