| OLD | NEW |
| 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/browser/dom_ui/shared_resources_data_source.h" | 5 #include "chrome/browser/dom_ui/shared_resources_data_source.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 break; | 46 break; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 return idr; | 51 return idr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 // static | |
| 57 void SharedResourcesDataSource::Register() { | |
| 58 SharedResourcesDataSource* source = new SharedResourcesDataSource(); | |
| 59 BrowserThread::PostTask( | |
| 60 BrowserThread::IO, FROM_HERE, | |
| 61 NewRunnableMethod( | |
| 62 ChromeURLDataManager::GetInstance(), | |
| 63 &ChromeURLDataManager::AddDataSource, | |
| 64 make_scoped_refptr(source))); | |
| 65 } | |
| 66 | |
| 67 SharedResourcesDataSource::SharedResourcesDataSource() | 56 SharedResourcesDataSource::SharedResourcesDataSource() |
| 68 : DataSource(chrome::kChromeUIResourcesHost, NULL) { | 57 : DataSource(chrome::kChromeUIResourcesHost, NULL) { |
| 69 } | 58 } |
| 70 | 59 |
| 71 SharedResourcesDataSource::~SharedResourcesDataSource() { | 60 SharedResourcesDataSource::~SharedResourcesDataSource() { |
| 72 } | 61 } |
| 73 | 62 |
| 74 void SharedResourcesDataSource::StartDataRequest(const std::string& path, | 63 void SharedResourcesDataSource::StartDataRequest(const std::string& path, |
| 75 bool is_off_the_record, | 64 bool is_off_the_record, |
| 76 int request_id) { | 65 int request_id) { |
| 77 int idr = PathToIDR(path); | 66 int idr = PathToIDR(path); |
| 78 DCHECK_NE(-1, idr); | 67 DCHECK_NE(-1, idr); |
| 79 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 68 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 80 scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(idr)); | 69 scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(idr)); |
| 81 SendResponse(request_id, bytes); | 70 SendResponse(request_id, bytes); |
| 82 } | 71 } |
| 83 | 72 |
| 84 std::string SharedResourcesDataSource::GetMimeType( | 73 std::string SharedResourcesDataSource::GetMimeType( |
| 85 const std::string& path) const { | 74 const std::string& path) const { |
| 86 // Requests should not block on the disk! On Windows this goes to the | 75 // Requests should not block on the disk! On Windows this goes to the |
| 87 // registry. | 76 // registry. |
| 88 // http://code.google.com/p/chromium/issues/detail?id=59849 | 77 // http://code.google.com/p/chromium/issues/detail?id=59849 |
| 89 base::ThreadRestrictions::ScopedAllowIO allow_io; | 78 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 90 | 79 |
| 91 std::string mime_type; | 80 std::string mime_type; |
| 92 net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); | 81 net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); |
| 93 return mime_type; | 82 return mime_type; |
| 94 } | 83 } |
| OLD | NEW |