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

Side by Side Diff: chrome/renderer/resources/extensions/app_runtime_custom_bindings.js

Issue 14607023: Add support for persistent file access in apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 7 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) 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 // Custom binding for the chrome.app.runtime API. 5 // Custom binding for the chrome.app.runtime API.
6 6
7 var binding = require('binding').Binding.create('app.runtime'); 7 var binding = require('binding').Binding.create('app.runtime');
8 8
9 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 9 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
10 var chrome = requireNative('chrome').GetChrome(); 10 var chrome = requireNative('chrome').GetChrome();
11 var fileSystemHelpers = requireNative('file_system_natives'); 11 var fileSystemHelpers = requireNative('file_system_natives');
12 var forEach = require('utils').forEach; 12 var forEach = require('utils').forEach;
13 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; 13 var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem;
14 var appNatives = requireNative('app_runtime'); 14 var appNatives = requireNative('app_runtime');
15 var DeserializeString = appNatives.DeserializeString; 15 var DeserializeString = appNatives.DeserializeString;
16 var SerializeToString = appNatives.SerializeToString; 16 var SerializeToString = appNatives.SerializeToString;
17 var CreateBlob = appNatives.CreateBlob; 17 var CreateBlob = appNatives.CreateBlob;
18 var entryIdManager = require('entryIdManager'); 18 var entryIdManager = require('entryIdManager');
19 19
20 chromeHidden.Event.registerArgumentMassager('app.runtime.onRestarted',
21 function(args, dispatch) {
22 // These file entries don't get dispatched, we just use this hook to register
23 // them all with entryIdManager.
24 var fileEntries = args[0];
25
26 var pendingCallbacks = fileEntries.length;
27
28 var dispatchIfNoPendingCallbacks = function() {
29 if (pendingCallbacks == 0)
30 dispatch([]);
31 };
32
33 for (var i = 0; i < fileEntries.length; i++) {
34 var fe = fileEntries[i];
35 var fs = GetIsolatedFileSystem(fe.fileSystemId);
36 (function(fe, fs) {
37 fs.root.getFile(fe.baseName, {}, function(fileEntry) {
38 entryIdManager.registerEntry(fe.id, fileEntry);
39 pendingCallbacks--;
40 dispatchIfNoPendingCallbacks();
41 }, function(err) {
42 console.error('Error getting fileEntry, code: ' + err.code);
43 pendingCallbacks--;
44 dispatchIfNoPendingCallbacks();
45 });
46 })(fe, fs);
47 }
48 dispatchIfNoPendingCallbacks();
49 });
50
51 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched', 20 chromeHidden.Event.registerArgumentMassager('app.runtime.onLaunched',
52 function(args, dispatch) { 21 function(args, dispatch) {
53 var launchData = args[0]; 22 var launchData = args[0];
54 23
55 if (launchData && typeof launchData.id !== 'undefined') { 24 if (launchData && typeof launchData.id !== 'undefined') {
56 // new-style dispatch. 25 // new-style dispatch.
57 var items = [] 26 var items = []
58 var numItems = launchData.items.length; 27 var numItems = launchData.items.length;
59 var itemLoaded = function(err, item) { 28 var itemLoaded = function(err, item) {
60 if (err) { 29 if (err) {
(...skipping 20 matching lines...) Expand all
81 }); 50 });
82 }); 51 });
83 } else if (launchData) { 52 } else if (launchData) {
84 dispatch([launchData]); 53 dispatch([launchData]);
85 } else { 54 } else {
86 dispatch([]); 55 dispatch([]);
87 } 56 }
88 }); 57 });
89 58
90 exports.binding = binding.generate(); 59 exports.binding = binding.generate();
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/file_system_natives.cc ('k') | chrome/renderer/resources/extensions/entry_id_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698