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

Side by Side Diff: chrome/common/extensions/docs/examples/api/transientPage/basic/background.js

Issue 10217018: Alarm resolution changed to minutes and minimum delay added. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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 // Global variables only exist for the life of the page, so they get reset 5 // Global variables only exist for the life of the page, so they get reset
6 // each time the page is unloaded. 6 // each time the page is unloaded.
7 var counter = 1; 7 var counter = 1;
8 8
9 var lastTabId = -1; 9 var lastTabId = -1;
10 function sendMessage() { 10 function sendMessage() {
(...skipping 25 matching lines...) Expand all
36 chrome.tabs.executeScript({file: "content.js"}, function() { 36 chrome.tabs.executeScript({file: "content.js"}, function() {
37 // Note: we also sent a message above, upon loading the transient page, 37 // Note: we also sent a message above, upon loading the transient page,
38 // but the content script will not be loaded at that point, so we send 38 // but the content script will not be loaded at that point, so we send
39 // another here. 39 // another here.
40 sendMessage(); 40 sendMessage();
41 }); 41 });
42 }); 42 });
43 43
44 chrome.extension.onMessage.addListener(function(msg, _, sendResponse) { 44 chrome.extension.onMessage.addListener(function(msg, _, sendResponse) {
45 if (msg.setAlarm) { 45 if (msg.setAlarm) {
46 chrome.experimental.alarms.create({delayInSeconds: 5}); 46 chrome.experimental.alarms.create({delayInMinutes: 0.1});
47 } else if (msg.delayedResponse) { 47 } else if (msg.delayedResponse) {
48 // Note: setTimeout itself does NOT keep the page awake. We return true 48 // Note: setTimeout itself does NOT keep the page awake. We return true
49 // from the onMessage event handler, which keeps the message channel open - 49 // from the onMessage event handler, which keeps the message channel open -
50 // in turn keeping the transient page awake - until we call sendResponse. 50 // in turn keeping the transient page awake - until we call sendResponse.
51 setTimeout(function() { 51 setTimeout(function() {
52 sendResponse("Got your message."); 52 sendResponse("Got your message.");
53 }, 5000); 53 }, 5000);
54 return true; 54 return true;
55 } else if (msg.getCounters) { 55 } else if (msg.getCounters) {
56 sendResponse({counter: counter++, 56 sendResponse({counter: counter++,
(...skipping 11 matching lines...) Expand all
68 function() { 68 function() {
69 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 69 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
70 // After the unload event listener runs, the page will unload, so any 70 // After the unload event listener runs, the page will unload, so any
71 // asynchronous callbacks will not fire. 71 // asynchronous callbacks will not fire.
72 alert("This does not show up."); 72 alert("This does not show up.");
73 }); 73 });
74 console.log("Unloading."); 74 console.log("Unloading.");
75 chrome.browserAction.setBadgeText({text: ""}); 75 chrome.browserAction.setBadgeText({text: ""});
76 chrome.tabs.sendMessage(lastTabId, "Background page unloaded."); 76 chrome.tabs.sendMessage(lastTabId, "Background page unloaded.");
77 }); 77 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698