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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 10970026: Fix drive-by memory leak in media_galleries_api.cc. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: include scoped_ptr Created 8 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Implements the Chrome Extensions Media Galleries API. 5 // Implements the Chrome Extensions Media Galleries API.
6 6
7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h"
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/scoped_ptr.h"
13 #include "base/platform_file.h" 14 #include "base/platform_file.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/extensions/shell_window_registry.h" 17 #include "chrome/browser/extensions/shell_window_registry.h"
17 #include "chrome/browser/media_gallery/media_file_system_registry.h" 18 #include "chrome/browser/media_gallery/media_file_system_registry.h"
18 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" 19 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h"
19 #include "chrome/browser/ui/chrome_select_file_policy.h" 20 #include "chrome/browser/ui/chrome_select_file_policy.h"
20 #include "chrome/browser/ui/extensions/shell_window.h" 21 #include "chrome/browser/ui/extensions/shell_window.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents.h"
22 #include "chrome/common/extensions/api/experimental_media_galleries.h" 23 #include "chrome/common/extensions/api/experimental_media_galleries.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 render_view_host(), GetExtension(), base::Bind( 108 render_view_host(), GetExtension(), base::Bind(
108 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this)); 109 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this));
109 } 110 }
110 111
111 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( 112 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
112 const std::vector<MediaFileSystemInfo>& filesystems) { 113 const std::vector<MediaFileSystemInfo>& filesystems) {
113 const int child_id = render_view_host()->GetProcess()->GetID(); 114 const int child_id = render_view_host()->GetProcess()->GetID();
114 std::set<std::string> file_system_names; 115 std::set<std::string> file_system_names;
115 base::ListValue* list = new base::ListValue(); 116 base::ListValue* list = new base::ListValue();
116 for (size_t i = 0; i < filesystems.size(); i++) { 117 for (size_t i = 0; i < filesystems.size(); i++) {
117 base::DictionaryValue* file_system_dict_value = new base::DictionaryValue(); 118 scoped_ptr<base::DictionaryValue> file_system_dict_value(
119 new base::DictionaryValue());
118 120
119 // Send the file system id so the renderer can create a valid FileSystem 121 // Send the file system id so the renderer can create a valid FileSystem
120 // object. 122 // object.
121 file_system_dict_value->SetWithoutPathExpansion( 123 file_system_dict_value->SetWithoutPathExpansion(
122 "fsid", Value::CreateStringValue(filesystems[i].fsid)); 124 "fsid", Value::CreateStringValue(filesystems[i].fsid));
123 125
124 // The name must be unique according to the HTML5 File System API spec. 126 // The name must be unique according to the HTML5 File System API spec.
125 if (ContainsKey(file_system_names, filesystems[i].name)) { 127 if (ContainsKey(file_system_names, filesystems[i].name)) {
126 NOTREACHED() << "Duplicate file system name: " << filesystems[i].name; 128 NOTREACHED() << "Duplicate file system name: " << filesystems[i].name;
127 continue; 129 continue;
128 } 130 }
129 file_system_names.insert(filesystems[i].name); 131 file_system_names.insert(filesystems[i].name);
130 file_system_dict_value->SetWithoutPathExpansion( 132 file_system_dict_value->SetWithoutPathExpansion(
131 "name", Value::CreateStringValue(filesystems[i].name)); 133 "name", Value::CreateStringValue(filesystems[i].name));
132 134
133 list->Append(file_system_dict_value); 135 list->Append(file_system_dict_value.release());
134 136
135 if (!filesystems[i].path.empty() && 137 if (!filesystems[i].path.empty() &&
136 MediaGalleriesPermission::HasReadAccess(*GetExtension())) { 138 MediaGalleriesPermission::HasReadAccess(*GetExtension())) {
137 content::ChildProcessSecurityPolicy* policy = 139 content::ChildProcessSecurityPolicy* policy =
138 ChildProcessSecurityPolicy::GetInstance(); 140 ChildProcessSecurityPolicy::GetInstance();
139 if (!policy->CanReadFile(child_id, filesystems[i].path)) 141 if (!policy->CanReadFile(child_id, filesystems[i].path))
140 policy->GrantReadFile(child_id, filesystems[i].path); 142 policy->GrantReadFile(child_id, filesystems[i].path);
141 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); 143 policy->GrantReadFileSystem(child_id, filesystems[i].fsid);
142 } 144 }
143 // TODO(vandebo) Handle write permission. 145 // TODO(vandebo) Handle write permission.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { 179 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() {
178 if (!ApiIsAccessible(&error_)) 180 if (!ApiIsAccessible(&error_))
179 return false; 181 return false;
180 182
181 // TODO(vandebo) Update the metadata and return the new file. 183 // TODO(vandebo) Update the metadata and return the new file.
182 SetResult(Value::CreateNullValue()); 184 SetResult(Value::CreateNullValue());
183 return true; 185 return true;
184 } 186 }
185 187
186 } // namespace extensions 188 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698