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

Side by Side Diff: webkit/glue/plugins/pepper_file_ref.cc

Issue 2800028: Simplfy Pepepr2 bolierplate code. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Updated. Created 10 years, 5 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
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 "webkit/glue/plugins/pepper_file_ref.h" 5 #include "webkit/glue/plugins/pepper_file_ref.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "webkit/glue/plugins/pepper_plugin_instance.h" 8 #include "webkit/glue/plugins/pepper_plugin_instance.h"
9 #include "webkit/glue/plugins/pepper_var.h" 9 #include "webkit/glue/plugins/pepper_var.h"
10 #include "webkit/glue/plugins/pepper_resource_tracker.h" 10 #include "webkit/glue/plugins/pepper_resource_tracker.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 PP_Resource CreatePersistentFileRef(PP_Instance instance_id, const char* path) { 57 PP_Resource CreatePersistentFileRef(PP_Instance instance_id, const char* path) {
58 return CreateFileRef(instance_id, PP_FileSystemType_LocalPersistent, path); 58 return CreateFileRef(instance_id, PP_FileSystemType_LocalPersistent, path);
59 } 59 }
60 60
61 PP_Resource CreateTemporaryFileRef(PP_Instance instance_id, const char* path) { 61 PP_Resource CreateTemporaryFileRef(PP_Instance instance_id, const char* path) {
62 return CreateFileRef(instance_id, PP_FileSystemType_LocalTemporary, path); 62 return CreateFileRef(instance_id, PP_FileSystemType_LocalTemporary, path);
63 } 63 }
64 64
65 bool IsFileRef(PP_Resource resource) { 65 bool IsFileRef(PP_Resource resource) {
66 return !!ResourceTracker::Get()->GetAsFileRef(resource).get(); 66 return !!Resource::GetAs<FileRef>(resource).get();
67 } 67 }
68 68
69 PP_FileSystemType GetFileSystemType(PP_Resource file_ref_id) { 69 PP_FileSystemType GetFileSystemType(PP_Resource file_ref_id) {
70 scoped_refptr<FileRef> file_ref( 70 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
71 ResourceTracker::Get()->GetAsFileRef(file_ref_id));
72 if (!file_ref.get()) 71 if (!file_ref.get())
73 return PP_FileSystemType_External; 72 return PP_FileSystemType_External;
74 73
75 return file_ref->file_system_type(); 74 return file_ref->file_system_type();
76 } 75 }
77 76
78 PP_Var GetName(PP_Resource file_ref_id) { 77 PP_Var GetName(PP_Resource file_ref_id) {
79 scoped_refptr<FileRef> file_ref( 78 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
80 ResourceTracker::Get()->GetAsFileRef(file_ref_id));
81 if (!file_ref.get()) 79 if (!file_ref.get())
82 return PP_MakeVoid(); 80 return PP_MakeVoid();
83 81
84 return StringToPPVar(file_ref->GetName()); 82 return StringToPPVar(file_ref->GetName());
85 } 83 }
86 84
87 PP_Var GetPath(PP_Resource file_ref_id) { 85 PP_Var GetPath(PP_Resource file_ref_id) {
88 scoped_refptr<FileRef> file_ref( 86 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
89 ResourceTracker::Get()->GetAsFileRef(file_ref_id));
90 if (!file_ref.get()) 87 if (!file_ref.get())
91 return PP_MakeVoid(); 88 return PP_MakeVoid();
92 89
93 if (file_ref->file_system_type() == PP_FileSystemType_External) 90 if (file_ref->file_system_type() == PP_FileSystemType_External)
94 return PP_MakeVoid(); 91 return PP_MakeVoid();
95 92
96 return StringToPPVar(file_ref->path()); 93 return StringToPPVar(file_ref->path());
97 } 94 }
98 95
99 PP_Resource GetParent(PP_Resource file_ref_id) { 96 PP_Resource GetParent(PP_Resource file_ref_id) {
100 scoped_refptr<FileRef> file_ref( 97 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
101 ResourceTracker::Get()->GetAsFileRef(file_ref_id));
102 if (!file_ref.get()) 98 if (!file_ref.get())
103 return 0; 99 return 0;
104 100
105 if (file_ref->file_system_type() == PP_FileSystemType_External) 101 if (file_ref->file_system_type() == PP_FileSystemType_External)
106 return 0; 102 return 0;
107 103
108 scoped_refptr<FileRef> parent_ref(file_ref->GetParent()); 104 scoped_refptr<FileRef> parent_ref(file_ref->GetParent());
109 if (!parent_ref.get()) 105 if (!parent_ref.get())
110 return 0; 106 return 0;
111 parent_ref->AddRef(); // AddRef for the caller. 107 parent_ref->AddRef(); // AddRef for the caller.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (pos == 0) 162 if (pos == 0)
167 pos++; 163 pos++;
168 std::string parent_path = path_.substr(0, pos); 164 std::string parent_path = path_.substr(0, pos);
169 165
170 FileRef* parent_ref = new FileRef(module(), fs_type_, parent_path, origin_); 166 FileRef* parent_ref = new FileRef(module(), fs_type_, parent_path, origin_);
171 parent_ref->AddRef(); // AddRef for the caller. 167 parent_ref->AddRef(); // AddRef for the caller.
172 return parent_ref; 168 return parent_ref;
173 } 169 }
174 170
175 } // namespace pepper 171 } // namespace pepper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698